Skip to content

Commit

Permalink
fix #367
Browse files Browse the repository at this point in the history
  • Loading branch information
inc2734 committed Sep 2, 2024
1 parent edcda4c commit 6c7244f
Show file tree
Hide file tree
Showing 48 changed files with 584 additions and 724 deletions.
16 changes: 6 additions & 10 deletions src/blocks/both-sides/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,13 @@ registerBlockType( 'unitone/both-sides', {
const withChildBlockAttributes = createHigherOrderComponent(
( BlockListBlock ) => {
return ( props ) => {
const { getBlockParents, getBlock } = useSelect( blockEditorStore );
const { getBlock } = useSelect( blockEditorStore );

const blockParents = getBlockParents( props.clientId );
if ( 1 > blockParents.length ) {
if ( ! props.rootClientId ) {
return <BlockListBlock { ...props } />;
}

const parentClientId = blockParents[ blockParents.length - 1 ];
if ( ! parentClientId ) {
return <BlockListBlock { ...props } />;
}

const parentBlock = getBlock( parentClientId );
const parentBlock = getBlock( props.rootClientId );
if ( 'unitone/both-sides' !== parentBlock?.name ) {
return <BlockListBlock { ...props } />;
}
Expand All @@ -59,6 +53,7 @@ const withChildBlockAttributes = createHigherOrderComponent(
: DEFAULT_VALUES.flexBasis,
},
__unstableUnitoneSupports: {
...props?.attributes?.__unstableUnitoneSupports,
flexBasis: {
default: DEFAULT_VALUES.flexBasis,
},
Expand All @@ -75,5 +70,6 @@ const withChildBlockAttributes = createHigherOrderComponent(
addFilter(
'editor.BlockListBlock',
'unitone/both-sides/with-child-block-attributes',
withChildBlockAttributes
withChildBlockAttributes,
11
);
16 changes: 6 additions & 10 deletions src/blocks/flex-divided/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,13 @@ registerBlockType( 'unitone/flex-divided', {
const withChildBlockAttributes = createHigherOrderComponent(
( BlockListBlock ) => {
return ( props ) => {
const { getBlockParents, getBlock } = useSelect( blockEditorStore );
const { getBlock } = useSelect( blockEditorStore );

const blockParents = getBlockParents( props.clientId );
if ( 1 > blockParents.length ) {
if ( ! props.rootClientId ) {
return <BlockListBlock { ...props } />;
}

const parentClientId = blockParents[ blockParents.length - 1 ];
if ( ! parentClientId ) {
return <BlockListBlock { ...props } />;
}

const parentBlock = getBlock( parentClientId );
const parentBlock = getBlock( props.rootClientId );
if ( 'unitone/flex-divided' !== parentBlock?.name ) {
return <BlockListBlock { ...props } />;
}
Expand Down Expand Up @@ -69,6 +63,7 @@ const withChildBlockAttributes = createHigherOrderComponent(
: DEFAULT_VALUES.flexBasis,
},
__unstableUnitoneSupports: {
...props?.attributes?.__unstableUnitoneSupports,
flexGrow: {
default: DEFAULT_VALUES.flexGrow,
},
Expand All @@ -91,5 +86,6 @@ const withChildBlockAttributes = createHigherOrderComponent(
addFilter(
'editor.BlockListBlock',
'unitone/flex-divided/with-child-block-attributes',
withChildBlockAttributes
withChildBlockAttributes,
11
);
16 changes: 6 additions & 10 deletions src/blocks/flex/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,13 @@ registerBlockType( 'unitone/flex', {
const withChildBlockAttributes = createHigherOrderComponent(
( BlockListBlock ) => {
return ( props ) => {
const { getBlockParents, getBlock } = useSelect( blockEditorStore );
const { getBlock } = useSelect( blockEditorStore );

const blockParents = getBlockParents( props.clientId );
if ( 1 > blockParents.length ) {
if ( ! props.rootClientId ) {
return <BlockListBlock { ...props } />;
}

const parentClientId = blockParents[ blockParents.length - 1 ];
if ( ! parentClientId ) {
return <BlockListBlock { ...props } />;
}

const parentBlock = getBlock( parentClientId );
const parentBlock = getBlock( props.rootClientId );
if ( 'unitone/flex' !== parentBlock?.name ) {
return <BlockListBlock { ...props } />;
}
Expand Down Expand Up @@ -67,6 +61,7 @@ const withChildBlockAttributes = createHigherOrderComponent(
: DEFAULT_VALUES.flexBasis,
},
__unstableUnitoneSupports: {
...props?.attributes?.__unstableUnitoneSupports,
flexGrow: {
default: DEFAULT_VALUES.flexGrow,
},
Expand All @@ -89,5 +84,6 @@ const withChildBlockAttributes = createHigherOrderComponent(
addFilter(
'editor.BlockListBlock',
'unitone/flex/with-child-block-attributes',
withChildBlockAttributes
withChildBlockAttributes,
11
);
16 changes: 6 additions & 10 deletions src/blocks/grid-divided/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,13 @@ registerBlockType( 'unitone/grid-divided', {
const withChildBlockAttributes = createHigherOrderComponent(
( BlockListBlock ) => {
return ( props ) => {
const { getBlockParents, getBlock } = useSelect( blockEditorStore );
const { getBlock } = useSelect( blockEditorStore );

const blockParents = getBlockParents( props.clientId );
if ( 1 > blockParents.length ) {
if ( ! props.rootClientId ) {
return <BlockListBlock { ...props } />;
}

const parentClientId = blockParents[ blockParents.length - 1 ];
if ( ! parentClientId ) {
return <BlockListBlock { ...props } />;
}

const parentBlock = getBlock( parentClientId );
const parentBlock = getBlock( props.rootClientId );
if ( 'unitone/grid-divided' !== parentBlock?.name ) {
return <BlockListBlock { ...props } />;
}
Expand Down Expand Up @@ -68,6 +62,7 @@ const withChildBlockAttributes = createHigherOrderComponent(
: DEFAULT_VALUES.justifySelf,
},
__unstableUnitoneSupports: {
...props?.attributes?.__unstableUnitoneSupports,
alignSelf: {
responsive: true,
default: DEFAULT_VALUES.alignSelf,
Expand All @@ -89,5 +84,6 @@ const withChildBlockAttributes = createHigherOrderComponent(
addFilter(
'editor.BlockListBlock',
'unitone/grid/with-child-block-attributes',
withChildBlockAttributes
withChildBlockAttributes,
11
);
16 changes: 6 additions & 10 deletions src/blocks/grid/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,13 @@ registerBlockType( 'unitone/grid', {
const withChildBlockAttributes = createHigherOrderComponent(
( BlockListBlock ) => {
return ( props ) => {
const { getBlockParents, getBlock } = useSelect( blockEditorStore );
const { getBlock } = useSelect( blockEditorStore );

const blockParents = getBlockParents( props.clientId );
if ( 1 > blockParents.length ) {
if ( ! props.rootClientId ) {
return <BlockListBlock { ...props } />;
}

const parentClientId = blockParents[ blockParents.length - 1 ];
if ( ! parentClientId ) {
return <BlockListBlock { ...props } />;
}

const parentBlock = getBlock( parentClientId );
const parentBlock = getBlock( props.rootClientId );
if ( 'unitone/grid' !== parentBlock?.name ) {
return <BlockListBlock { ...props } />;
}
Expand Down Expand Up @@ -81,6 +75,7 @@ const withChildBlockAttributes = createHigherOrderComponent(
: DEFAULT_VALUES.gridRow,
},
__unstableUnitoneSupports: {
...props?.attributes?.__unstableUnitoneSupports,
alignSelf: {
responsive: true,
default: DEFAULT_VALUES.alignSelf,
Expand Down Expand Up @@ -110,5 +105,6 @@ const withChildBlockAttributes = createHigherOrderComponent(
addFilter(
'editor.BlockListBlock',
'unitone/grid/with-child-block-attributes',
withChildBlockAttributes
withChildBlockAttributes,
11
);
5 changes: 2 additions & 3 deletions src/blocks/gutters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ const changeUnitoneSupportsLabels = createHigherOrderComponent(
__unstableUnitoneSupports: {
...props?.attributes?.__unstableUnitoneSupports,
padding: {
...props?.attributes?.__unstableUnitoneSupports
?.padding,
label: __( 'Top and bottom padding', 'unitone' ),
},
},
Expand All @@ -52,5 +50,6 @@ const changeUnitoneSupportsLabels = createHigherOrderComponent(
addFilter(
'editor.BlockListBlock',
'unitone/gutters/change-unitone-supports-labels',
changeUnitoneSupportsLabels
changeUnitoneSupportsLabels,
11
);
16 changes: 6 additions & 10 deletions src/blocks/layers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,13 @@ registerBlockType( 'unitone/layers', {
const withChildBlockAttributes = createHigherOrderComponent(
( BlockListBlock ) => {
return ( props ) => {
const { getBlockParents, getBlock } = useSelect( blockEditorStore );
const { getBlock } = useSelect( blockEditorStore );

const blockParents = getBlockParents( props.clientId );
if ( 1 > blockParents.length ) {
if ( ! props.rootClientId ) {
return <BlockListBlock { ...props } />;
}

const parentClientId = blockParents[ blockParents.length - 1 ];
if ( ! parentClientId ) {
return <BlockListBlock { ...props } />;
}

const parentBlock = getBlock( parentClientId );
const parentBlock = getBlock( props.rootClientId );
if ( 'unitone/layers' !== parentBlock?.name ) {
return <BlockListBlock { ...props } />;
}
Expand Down Expand Up @@ -76,6 +70,7 @@ const withChildBlockAttributes = createHigherOrderComponent(
: DEFAULT_VALUES.gridRow,
},
__unstableUnitoneSupports: {
...props?.attributes?.__unstableUnitoneSupports,
alignSelf: {
default: DEFAULT_VALUES.alignSelf,
},
Expand Down Expand Up @@ -104,5 +99,6 @@ const withChildBlockAttributes = createHigherOrderComponent(
addFilter(
'editor.BlockListBlock',
'unitone/layers/with-child-block-attributes',
withChildBlockAttributes
withChildBlockAttributes,
11
);
7 changes: 2 additions & 5 deletions src/blocks/section/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,9 @@ const changeUnitoneSupportsLabels = createHigherOrderComponent(
__unstableUnitoneSupports: {
...props?.attributes?.__unstableUnitoneSupports,
maxWidth: {
...props?.attributes?.__unstableUnitoneSupports
?.maxWidth,
label: __( 'Max width of contents', 'unitone' ),
},
padding: {
...props?.attributes?.__unstableUnitoneSupports
?.padding,
label: __( 'Top and bottom padding', 'unitone' ),
},
},
Expand All @@ -58,5 +54,6 @@ const changeUnitoneSupportsLabels = createHigherOrderComponent(
addFilter(
'editor.BlockListBlock',
'unitone/gutters/change-unitone-supports-labels',
changeUnitoneSupportsLabels
changeUnitoneSupportsLabels,
11
);
6 changes: 3 additions & 3 deletions src/js/editor/hooks/animation/animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ import {
hasParallaxValue,
resetParallax,
ParallaxEdit,
editParallaxProp,
useParallaxBlockProps,
} from './parallax';

import {
useIsScrollAnimationDisabled,
hasScrollAnimationValue,
resetScrollAnimation,
ScrollAnimationEdit,
editScrollAnimationProp,
useScrollAnimationBlockProps,
} from './scroll-animation';

export { editParallaxProp, editScrollAnimationProp };
export { useParallaxBlockProps, useScrollAnimationBlockProps };

export function AnimationPanel( props ) {
const isParallaxDisabled = useIsParallaxDisabled( props );
Expand Down
19 changes: 9 additions & 10 deletions src/js/editor/hooks/animation/parallax.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,14 @@ export function saveParallaxProp( extraProps, blockType, attributes ) {
return extraProps;
}

export function editParallaxProp( settings ) {
const existingGetEditWrapperProps = settings.getEditWrapperProps;
settings.getEditWrapperProps = ( attributes ) => {
let props = {};
if ( existingGetEditWrapperProps ) {
props = existingGetEditWrapperProps( attributes );
}
return saveParallaxProp( props, settings, attributes );
export function useParallaxBlockProps( settings ) {
const { attributes, name, wrapperProps } = settings;

return {
...settings,
wrapperProps: {
...settings.wrapperProps,
...saveParallaxProp( wrapperProps, name, attributes ),
},
};

return settings;
}
19 changes: 9 additions & 10 deletions src/js/editor/hooks/animation/scroll-animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,15 +433,14 @@ export function saveScrollAnimationProp( extraProps, blockType, attributes ) {
return extraProps;
}

export function editScrollAnimationProp( settings ) {
const existingGetEditWrapperProps = settings.getEditWrapperProps;
settings.getEditWrapperProps = ( attributes ) => {
let props = {};
if ( existingGetEditWrapperProps ) {
props = existingGetEditWrapperProps( attributes );
}
return saveScrollAnimationProp( props, settings, attributes );
export function useScrollAnimationBlockProps( settings ) {
const { attributes, name, wrapperProps } = settings;

return {
...settings,
wrapperProps: {
...settings.wrapperProps,
...saveScrollAnimationProp( wrapperProps, name, attributes ),
},
};

return settings;
}
4 changes: 2 additions & 2 deletions src/js/editor/hooks/border/border.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
resetDropShadow,
getDropShadowEditLabel,
DropShadowEdit,
editDropShadowProp,
useDropShadowBlockProps,
} from './drop-shadow';

export { editDropShadowProp };
export { useDropShadowBlockProps };

export function DropShadowPanel( props ) {
const isDropShadowDisabled = useIsDropShadowDisabled( props );
Expand Down
22 changes: 9 additions & 13 deletions src/js/editor/hooks/border/drop-shadow.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,18 +314,14 @@ export function saveDropShadowProp( extraProps, blockType, attributes ) {
return extraProps;
}

export function editDropShadowProp( settings ) {
if ( ! hasBlockSupport( settings, 'unitone.dropShadow' ) ) {
return settings;
}

const existingGetEditWrapperProps = settings.getEditWrapperProps;
settings.getEditWrapperProps = ( attributes ) => {
let props = {};
if ( existingGetEditWrapperProps ) {
props = existingGetEditWrapperProps( attributes );
}
return saveDropShadowProp( props, settings, attributes );
export function useDropShadowBlockProps( settings ) {
const { attributes, name, wrapperProps } = settings;

return {
...settings,
wrapperProps: {
...settings.wrapperProps,
...saveDropShadowProp( wrapperProps, name, attributes ),
},
};
return settings;
}
Loading

0 comments on commit 6c7244f

Please sign in to comment.