@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.
Files changed (49) hide show
  1. package/build/components/block-parent-selector/index.js +2 -2
  2. package/build/components/block-parent-selector/index.js.map +1 -1
  3. package/build/components/block-popover/inbetween.js +3 -1
  4. package/build/components/block-popover/inbetween.js.map +1 -1
  5. package/build/components/block-popover/index.js +19 -16
  6. package/build/components/block-popover/index.js.map +1 -1
  7. package/build/components/image-editor/use-transform-image.js +2 -2
  8. package/build/components/image-editor/use-transform-image.js.map +1 -1
  9. package/build/components/spacing-sizes-control/index.js +10 -2
  10. package/build/components/spacing-sizes-control/index.js.map +1 -1
  11. package/build/components/spacing-sizes-control/spacing-input-control.js +5 -4
  12. package/build/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
  13. package/build/hooks/index.js +13 -1
  14. package/build/hooks/index.js.map +1 -1
  15. package/build/hooks/layout.js +76 -23
  16. package/build/hooks/layout.js.map +1 -1
  17. package/build/index.js +14 -0
  18. package/build/index.js.map +1 -1
  19. package/build-module/components/block-parent-selector/index.js +2 -2
  20. package/build-module/components/block-parent-selector/index.js.map +1 -1
  21. package/build-module/components/block-popover/inbetween.js +3 -1
  22. package/build-module/components/block-popover/inbetween.js.map +1 -1
  23. package/build-module/components/block-popover/index.js +19 -16
  24. package/build-module/components/block-popover/index.js.map +1 -1
  25. package/build-module/components/image-editor/use-transform-image.js +2 -2
  26. package/build-module/components/image-editor/use-transform-image.js.map +1 -1
  27. package/build-module/components/spacing-sizes-control/index.js +10 -3
  28. package/build-module/components/spacing-sizes-control/index.js.map +1 -1
  29. package/build-module/components/spacing-sizes-control/spacing-input-control.js +6 -5
  30. package/build-module/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
  31. package/build-module/hooks/index.js +1 -0
  32. package/build-module/hooks/index.js.map +1 -1
  33. package/build-module/hooks/layout.js +73 -23
  34. package/build-module/hooks/layout.js.map +1 -1
  35. package/build-module/index.js +1 -1
  36. package/build-module/index.js.map +1 -1
  37. package/build-style/style-rtl.css +24 -19
  38. package/build-style/style.css +24 -19
  39. package/package.json +9 -9
  40. package/src/components/block-parent-selector/index.js +2 -2
  41. package/src/components/block-popover/inbetween.js +1 -1
  42. package/src/components/block-popover/index.js +36 -21
  43. package/src/components/image-editor/use-transform-image.js +2 -2
  44. package/src/components/spacing-sizes-control/index.js +15 -3
  45. package/src/components/spacing-sizes-control/spacing-input-control.js +8 -7
  46. package/src/components/spacing-sizes-control/style.scss +28 -24
  47. package/src/hooks/index.js +1 -0
  48. package/src/hooks/layout.js +64 -21
  49. package/src/index.js +2 -0
@@ -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 blocks layout attributes.
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 } layout Layout 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( layout, layoutDefinitions ) {
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 ( layoutDefinitions?.[ layout?.type || 'default' ]?.className ) {
66
+ if (
67
+ globalLayoutSettings?.definitions?.[ usedLayout?.type || 'default' ]
68
+ ?.className
69
+ ) {
61
70
  layoutClassnames.push(
62
- layoutDefinitions?.[ layout?.type || 'default' ]?.className
71
+ globalLayoutSettings?.definitions?.[ usedLayout?.type || 'default' ]
72
+ ?.className
63
73
  );
64
74
  }
65
75
 
66
76
  if (
67
- ( layout?.inherit ||
68
- layout?.contentSize ||
69
- layout?.type === 'constrained' ) &&
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 ( layout?.orientation ) {
76
- layoutClassnames.push( `is-${ kebabCase( layout.orientation ) }` );
85
+ if ( usedLayout?.orientation ) {
86
+ layoutClassnames.push( `is-${ kebabCase( usedLayout.orientation ) }` );
77
87
  }
78
88
 
79
- if ( layout?.justifyContent ) {
89
+ if ( usedLayout?.justifyContent ) {
80
90
  layoutClassnames.push(
81
- `is-content-justification-${ kebabCase( layout.justifyContent ) }`
91
+ `is-content-justification-${ kebabCase(
92
+ usedLayout.justifyContent
93
+ ) }`
82
94
  );
83
95
  }
84
96
 
85
- if ( layout?.flexWrap && layout.flexWrap === 'nowrap' ) {
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( usedLayout, defaultThemeLayout?.definitions )
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';