Skip to content

Commit 8947909

Browse files
draganescuclaude
andcommitted
Grid: Move getUpdatedChildLayoutStyle next to the block style state helpers
`components/grid` imported it from `hooks/layout-child`, which imports `components/grid`. It only merges a layout into a block style state, with the helpers in `hooks/block-style-state`, so it moves there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent bedba56 commit 8947909

4 files changed

Lines changed: 51 additions & 47 deletions

File tree

‎packages/block-editor/src/components/grid/grid-visualizer.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { store as blockEditorStore } from '../../store';
3030
import { useGetNumberOfBlocksBeforeCell } from './use-get-number-of-blocks-before-cell';
3131
import ButtonBlockAppender from '../button-block-appender';
3232
import { unlock } from '../../lock-unlock';
33-
import { getUpdatedChildLayoutStyle } from '../../hooks/layout-child';
33+
import { getUpdatedChildLayoutStyle } from '../../hooks/block-style-state';
3434
import type { ChildLayoutBlockStyle } from '../../hooks/types';
3535
import type {
3636
AutoGridVisualizerProps,

‎packages/block-editor/src/hooks/block-style-state.ts‎

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { createContext, useContext } from '@wordpress/element';
22
import { cleanEmptyObject } from './utils';
33
import { getValueFromObjectPath, setImmutably } from '../utils/object';
4-
import type { BlockStyle, BlockStyleState, ResetAllFilter } from './types';
4+
import type {
5+
BlockStyle,
6+
BlockStyleState,
7+
ChildLayoutBlockStyle,
8+
ResetAllFilter,
9+
} from './types';
10+
import type { ChildLayout } from '../components/child-layout-control/types';
511

612
const DEFAULT_STATE_VALUE = 'default';
713

@@ -182,3 +188,44 @@ export function scopeResetAllFilterToState<
182188
};
183189
};
184190
}
191+
192+
/**
193+
* Merges child layout changes into the active layout style state.
194+
*
195+
* @param style Block style attributes.
196+
* @param layout Child layout changes.
197+
* @param selectedState Selected block style state.
198+
* @return Updated block style attributes.
199+
*/
200+
export function getUpdatedChildLayoutStyle(
201+
style: ChildLayoutBlockStyle | undefined,
202+
layout: ChildLayout,
203+
selectedState: BlockStyleState | undefined
204+
): ChildLayoutBlockStyle | undefined {
205+
if ( ! hasViewportBlockStyleState( selectedState ) ) {
206+
return {
207+
...style,
208+
layout: {
209+
...style?.layout,
210+
...layout,
211+
},
212+
};
213+
}
214+
215+
const layoutState = {
216+
// A viewport state is selected here.
217+
viewport: selectedState!.viewport,
218+
pseudo: DEFAULT_BLOCK_STYLE_STATE.pseudo,
219+
};
220+
// A style state holds the child layout it overrides.
221+
const stateStyle = getStyleForState( style, layoutState ) as
222+
ChildLayoutBlockStyle | undefined;
223+
224+
return setStyleForState( style, layoutState, {
225+
...stateStyle,
226+
layout: {
227+
...stateStyle?.layout,
228+
...layout,
229+
},
230+
} );
231+
}

‎packages/block-editor/src/hooks/layout-child.tsx‎

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@ import { BLOCK_VISIBILITY_VIEWPORTS } from '../components/block-visibility/const
1818
import {
1919
DEFAULT_BLOCK_STYLE_STATE,
2020
getStyleForState,
21-
hasViewportBlockStyleState,
22-
setStyleForState,
21+
getUpdatedChildLayoutStyle,
2322
} from './block-style-state';
2423
import type {
25-
BlockStyleState,
2624
BlockListBlockFeatureProps,
2725
ChildLayoutBlockStyle,
2826
ChildLayoutControlsPureProps,
@@ -294,47 +292,6 @@ export function getResponsiveChildLayoutStyles( {
294292
.join( '' );
295293
}
296294

297-
/**
298-
* Merges child layout changes into the active layout style state.
299-
*
300-
* @param style Block style attributes.
301-
* @param layout Child layout changes.
302-
* @param selectedState Selected block style state.
303-
* @return Updated block style attributes.
304-
*/
305-
export function getUpdatedChildLayoutStyle(
306-
style: ChildLayoutBlockStyle | undefined,
307-
layout: ChildLayout,
308-
selectedState: BlockStyleState | undefined
309-
): ChildLayoutBlockStyle | undefined {
310-
if ( ! hasViewportBlockStyleState( selectedState ) ) {
311-
return {
312-
...style,
313-
layout: {
314-
...style?.layout,
315-
...layout,
316-
},
317-
};
318-
}
319-
320-
const layoutState = {
321-
// A viewport state is selected here.
322-
viewport: selectedState!.viewport,
323-
pseudo: DEFAULT_BLOCK_STYLE_STATE.pseudo,
324-
};
325-
// A style state holds the child layout it overrides.
326-
const stateStyle = getStyleForState( style, layoutState ) as
327-
ChildLayoutBlockStyle | undefined;
328-
329-
return setStyleForState( style, layoutState, {
330-
...stateStyle,
331-
layout: {
332-
...stateStyle?.layout,
333-
...layout,
334-
},
335-
} );
336-
}
337-
338295
function useBlockPropsChildLayoutStyles( {
339296
style,
340297
}: BlockListBlockFeatureProps & { style?: ChildLayoutBlockStyle } ) {

‎packages/block-editor/src/hooks/test/layout-child.jsdom.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import {
33
getChildLayoutStyleRules,
44
getChildLayoutStyles,
55
getResponsiveChildLayoutStyles,
6-
getUpdatedChildLayoutStyle,
76
} from '../layout-child';
7+
import { getUpdatedChildLayoutStyle } from '../block-style-state';
88

99
describe( 'layout child', () => {
1010
describe( 'getChildLayoutStyleRules()', () => {

0 commit comments

Comments
 (0)