@wordpress/block-editor 10.0.3 → 10.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/block-parent-selector/index.js +2 -2
- package/build/components/block-parent-selector/index.js.map +1 -1
- package/build/components/block-popover/inbetween.js +3 -1
- package/build/components/block-popover/inbetween.js.map +1 -1
- package/build/components/block-popover/index.js +19 -16
- package/build/components/block-popover/index.js.map +1 -1
- package/build/components/image-editor/use-transform-image.js +2 -2
- package/build/components/image-editor/use-transform-image.js.map +1 -1
- package/build/components/spacing-sizes-control/index.js +10 -2
- package/build/components/spacing-sizes-control/index.js.map +1 -1
- package/build/components/spacing-sizes-control/spacing-input-control.js +5 -4
- package/build/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
- package/build/hooks/index.js +13 -1
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/layout.js +76 -23
- package/build/hooks/layout.js.map +1 -1
- package/build/index.js +14 -0
- package/build/index.js.map +1 -1
- package/build-module/components/block-parent-selector/index.js +2 -2
- package/build-module/components/block-parent-selector/index.js.map +1 -1
- package/build-module/components/block-popover/inbetween.js +3 -1
- package/build-module/components/block-popover/inbetween.js.map +1 -1
- package/build-module/components/block-popover/index.js +19 -16
- package/build-module/components/block-popover/index.js.map +1 -1
- package/build-module/components/image-editor/use-transform-image.js +2 -2
- package/build-module/components/image-editor/use-transform-image.js.map +1 -1
- package/build-module/components/spacing-sizes-control/index.js +10 -3
- package/build-module/components/spacing-sizes-control/index.js.map +1 -1
- package/build-module/components/spacing-sizes-control/spacing-input-control.js +6 -5
- package/build-module/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/layout.js +73 -23
- package/build-module/hooks/layout.js.map +1 -1
- package/build-module/index.js +1 -1
- package/build-module/index.js.map +1 -1
- package/build-style/style-rtl.css +24 -19
- package/build-style/style.css +24 -19
- package/package.json +9 -9
- package/src/components/block-parent-selector/index.js +2 -2
- package/src/components/block-popover/inbetween.js +1 -1
- package/src/components/block-popover/index.js +36 -21
- package/src/components/image-editor/use-transform-image.js +2 -2
- package/src/components/spacing-sizes-control/index.js +15 -3
- package/src/components/spacing-sizes-control/spacing-input-control.js +8 -7
- package/src/components/spacing-sizes-control/style.scss +28 -24
- package/src/hooks/index.js +1 -0
- package/src/hooks/layout.js +64 -21
- package/src/index.js +2 -0
package/src/hooks/layout.js
CHANGED
|
@@ -37,58 +37,101 @@ import { getLayoutType, getLayoutTypes } from '../layouts';
|
|
|
37
37
|
const layoutBlockSupportKey = '__experimentalLayout';
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
|
-
* Generates the utility classnames for the given
|
|
41
|
-
* This method was primarily added to reintroduce classnames that were removed
|
|
42
|
-
* in the 5.9 release (https://github.com/WordPress/gutenberg/issues/38719), rather
|
|
43
|
-
* than providing an extensive list of all possible layout classes. The plan is to
|
|
44
|
-
* have the style engine generate a more extensive list of utility classnames which
|
|
45
|
-
* will then replace this method.
|
|
40
|
+
* Generates the utility classnames for the given block's layout attributes.
|
|
46
41
|
*
|
|
47
|
-
* @param { Object }
|
|
48
|
-
* @param { Object } layoutDefinitions An object containing layout definitions, stored in theme.json.
|
|
42
|
+
* @param { Object } block Block object.
|
|
49
43
|
*
|
|
50
44
|
* @return { Array } Array of CSS classname strings.
|
|
51
45
|
*/
|
|
52
|
-
function useLayoutClasses(
|
|
46
|
+
export function useLayoutClasses( block = {} ) {
|
|
53
47
|
const rootPaddingAlignment = useSelect( ( select ) => {
|
|
54
48
|
const { getSettings } = select( blockEditorStore );
|
|
55
49
|
return getSettings().__experimentalFeatures
|
|
56
50
|
?.useRootPaddingAwareAlignments;
|
|
57
51
|
}, [] );
|
|
52
|
+
const globalLayoutSettings = useSetting( 'layout' ) || {};
|
|
53
|
+
|
|
54
|
+
const { attributes = {}, name } = block;
|
|
55
|
+
const { layout } = attributes;
|
|
56
|
+
|
|
57
|
+
const { default: defaultBlockLayout } =
|
|
58
|
+
getBlockSupport( name, layoutBlockSupportKey ) || {};
|
|
59
|
+
const usedLayout =
|
|
60
|
+
layout?.inherit || layout?.contentSize || layout?.wideSize
|
|
61
|
+
? { ...layout, type: 'constrained' }
|
|
62
|
+
: layout || defaultBlockLayout || {};
|
|
63
|
+
|
|
58
64
|
const layoutClassnames = [];
|
|
59
65
|
|
|
60
|
-
if (
|
|
66
|
+
if (
|
|
67
|
+
globalLayoutSettings?.definitions?.[ usedLayout?.type || 'default' ]
|
|
68
|
+
?.className
|
|
69
|
+
) {
|
|
61
70
|
layoutClassnames.push(
|
|
62
|
-
|
|
71
|
+
globalLayoutSettings?.definitions?.[ usedLayout?.type || 'default' ]
|
|
72
|
+
?.className
|
|
63
73
|
);
|
|
64
74
|
}
|
|
65
75
|
|
|
66
76
|
if (
|
|
67
|
-
(
|
|
68
|
-
|
|
69
|
-
|
|
77
|
+
( usedLayout?.inherit ||
|
|
78
|
+
usedLayout?.contentSize ||
|
|
79
|
+
usedLayout?.type === 'constrained' ) &&
|
|
70
80
|
rootPaddingAlignment
|
|
71
81
|
) {
|
|
72
82
|
layoutClassnames.push( 'has-global-padding' );
|
|
73
83
|
}
|
|
74
84
|
|
|
75
|
-
if (
|
|
76
|
-
layoutClassnames.push( `is-${ kebabCase(
|
|
85
|
+
if ( usedLayout?.orientation ) {
|
|
86
|
+
layoutClassnames.push( `is-${ kebabCase( usedLayout.orientation ) }` );
|
|
77
87
|
}
|
|
78
88
|
|
|
79
|
-
if (
|
|
89
|
+
if ( usedLayout?.justifyContent ) {
|
|
80
90
|
layoutClassnames.push(
|
|
81
|
-
`is-content-justification-${ kebabCase(
|
|
91
|
+
`is-content-justification-${ kebabCase(
|
|
92
|
+
usedLayout.justifyContent
|
|
93
|
+
) }`
|
|
82
94
|
);
|
|
83
95
|
}
|
|
84
96
|
|
|
85
|
-
if (
|
|
97
|
+
if ( usedLayout?.flexWrap && usedLayout.flexWrap === 'nowrap' ) {
|
|
86
98
|
layoutClassnames.push( 'is-nowrap' );
|
|
87
99
|
}
|
|
88
100
|
|
|
89
101
|
return layoutClassnames;
|
|
90
102
|
}
|
|
91
103
|
|
|
104
|
+
/**
|
|
105
|
+
* Generates a CSS rule with the given block's layout styles.
|
|
106
|
+
*
|
|
107
|
+
* @param { Object } block Block object.
|
|
108
|
+
* @param { string } selector A selector to use in generating the CSS rule.
|
|
109
|
+
*
|
|
110
|
+
* @return { string } CSS rule.
|
|
111
|
+
*/
|
|
112
|
+
export function useLayoutStyles( block = {}, selector ) {
|
|
113
|
+
const { attributes = {}, name } = block;
|
|
114
|
+
const { layout = {}, style = {} } = attributes;
|
|
115
|
+
// Update type for blocks using legacy layouts.
|
|
116
|
+
const usedLayout =
|
|
117
|
+
layout?.inherit || layout?.contentSize || layout?.wideSize
|
|
118
|
+
? { ...layout, type: 'constrained' }
|
|
119
|
+
: layout || {};
|
|
120
|
+
const fullLayoutType = getLayoutType( usedLayout?.type || 'default' );
|
|
121
|
+
const globalLayoutSettings = useSetting( 'layout' ) || {};
|
|
122
|
+
const blockGapSupport = useSetting( 'spacing.blockGap' );
|
|
123
|
+
const hasBlockGapSupport = blockGapSupport !== null;
|
|
124
|
+
const css = fullLayoutType?.getLayoutStyle?.( {
|
|
125
|
+
blockName: name,
|
|
126
|
+
selector,
|
|
127
|
+
layout,
|
|
128
|
+
layoutDefinitions: globalLayoutSettings?.definitions,
|
|
129
|
+
style,
|
|
130
|
+
hasBlockGapSupport,
|
|
131
|
+
} );
|
|
132
|
+
return css;
|
|
133
|
+
}
|
|
134
|
+
|
|
92
135
|
function LayoutPanel( { setAttributes, attributes, name: blockName } ) {
|
|
93
136
|
const { layout } = attributes;
|
|
94
137
|
const defaultThemeLayout = useSetting( 'layout' );
|
|
@@ -299,7 +342,7 @@ export const withInspectorControls = createHigherOrderComponent(
|
|
|
299
342
|
*/
|
|
300
343
|
export const withLayoutStyles = createHigherOrderComponent(
|
|
301
344
|
( BlockListBlock ) => ( props ) => {
|
|
302
|
-
const { name, attributes } = props;
|
|
345
|
+
const { name, attributes, block } = props;
|
|
303
346
|
const hasLayoutBlockSupport = hasBlockSupport(
|
|
304
347
|
name,
|
|
305
348
|
layoutBlockSupportKey
|
|
@@ -321,7 +364,7 @@ export const withLayoutStyles = createHigherOrderComponent(
|
|
|
321
364
|
? { ...layout, type: 'constrained' }
|
|
322
365
|
: layout || defaultBlockLayout || {};
|
|
323
366
|
const layoutClasses = hasLayoutBlockSupport
|
|
324
|
-
? useLayoutClasses(
|
|
367
|
+
? useLayoutClasses( block )
|
|
325
368
|
: null;
|
|
326
369
|
const selector = `.${ getBlockDefaultClassName(
|
|
327
370
|
name
|
package/src/index.js
CHANGED
|
@@ -12,6 +12,8 @@ export {
|
|
|
12
12
|
getSpacingClassesAndStyles as __experimentalGetSpacingClassesAndStyles,
|
|
13
13
|
getGapCSSValue as __experimentalGetGapCSSValue,
|
|
14
14
|
useCachedTruthy,
|
|
15
|
+
useLayoutClasses as __experimentaluseLayoutClasses,
|
|
16
|
+
useLayoutStyles as __experimentaluseLayoutStyles,
|
|
15
17
|
} from './hooks';
|
|
16
18
|
export * from './components';
|
|
17
19
|
export * from './elements';
|