@wordpress/block-editor 10.0.2 → 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 (59) 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 +26 -9
  4. package/build/components/block-popover/inbetween.js.map +1 -1
  5. package/build/components/block-popover/index.js +34 -4
  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/list-view/index.js +2 -1
  10. package/build/components/list-view/index.js.map +1 -1
  11. package/build/components/rich-text/index.js +12 -0
  12. package/build/components/rich-text/index.js.map +1 -1
  13. package/build/components/spacing-sizes-control/index.js +10 -2
  14. package/build/components/spacing-sizes-control/index.js.map +1 -1
  15. package/build/components/spacing-sizes-control/spacing-input-control.js +5 -4
  16. package/build/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
  17. package/build/hooks/index.js +13 -1
  18. package/build/hooks/index.js.map +1 -1
  19. package/build/hooks/layout.js +76 -23
  20. package/build/hooks/layout.js.map +1 -1
  21. package/build/index.js +14 -0
  22. package/build/index.js.map +1 -1
  23. package/build-module/components/block-parent-selector/index.js +2 -2
  24. package/build-module/components/block-parent-selector/index.js.map +1 -1
  25. package/build-module/components/block-popover/inbetween.js +26 -9
  26. package/build-module/components/block-popover/inbetween.js.map +1 -1
  27. package/build-module/components/block-popover/index.js +34 -5
  28. package/build-module/components/block-popover/index.js.map +1 -1
  29. package/build-module/components/image-editor/use-transform-image.js +2 -2
  30. package/build-module/components/image-editor/use-transform-image.js.map +1 -1
  31. package/build-module/components/list-view/index.js +2 -1
  32. package/build-module/components/list-view/index.js.map +1 -1
  33. package/build-module/components/rich-text/index.js +12 -0
  34. package/build-module/components/rich-text/index.js.map +1 -1
  35. package/build-module/components/spacing-sizes-control/index.js +10 -3
  36. package/build-module/components/spacing-sizes-control/index.js.map +1 -1
  37. package/build-module/components/spacing-sizes-control/spacing-input-control.js +6 -5
  38. package/build-module/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
  39. package/build-module/hooks/index.js +1 -0
  40. package/build-module/hooks/index.js.map +1 -1
  41. package/build-module/hooks/layout.js +73 -23
  42. package/build-module/hooks/layout.js.map +1 -1
  43. package/build-module/index.js +1 -1
  44. package/build-module/index.js.map +1 -1
  45. package/build-style/style-rtl.css +24 -19
  46. package/build-style/style.css +24 -19
  47. package/package.json +10 -10
  48. package/src/components/block-parent-selector/index.js +2 -2
  49. package/src/components/block-popover/inbetween.js +35 -11
  50. package/src/components/block-popover/index.js +64 -4
  51. package/src/components/image-editor/use-transform-image.js +2 -2
  52. package/src/components/list-view/index.js +1 -0
  53. package/src/components/rich-text/index.js +14 -0
  54. package/src/components/spacing-sizes-control/index.js +15 -3
  55. package/src/components/spacing-sizes-control/spacing-input-control.js +8 -7
  56. package/src/components/spacing-sizes-control/style.scss +28 -24
  57. package/src/hooks/index.js +1 -0
  58. package/src/hooks/layout.js +64 -21
  59. package/src/index.js +2 -0
@@ -188,6 +188,7 @@ function ListView(
188
188
  onCollapseRow={ collapseRow }
189
189
  onExpandRow={ expandRow }
190
190
  onFocusRow={ focusRow }
191
+ applicationAriaLabel={ __( 'Block navigation structure' ) }
191
192
  >
192
193
  <ListViewContext.Provider value={ contextValue }>
193
194
  <ListViewBranch
@@ -173,6 +173,13 @@ function RichTextWrapper(
173
173
 
174
174
  // Handle deprecated format.
175
175
  if ( Array.isArray( originalValue ) ) {
176
+ deprecated( 'wp.blockEditor.RichText value prop as children type', {
177
+ since: '6.1',
178
+ version: '6.3',
179
+ alternative: 'value prop as string',
180
+ link: 'https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/introducing-attributes-and-editable-fields/',
181
+ } );
182
+
176
183
  adjustedValue = childrenSource.toHTML( originalValue );
177
184
  adjustedOnChange = ( newValue ) =>
178
185
  originalOnChange(
@@ -436,6 +443,13 @@ ForwardedRichTextContainer.Content = ( {
436
443
  } ) => {
437
444
  // Handle deprecated `children` and `node` sources.
438
445
  if ( Array.isArray( value ) ) {
446
+ deprecated( 'wp.blockEditor.RichText value prop as children type', {
447
+ since: '6.1',
448
+ version: '6.3',
449
+ alternative: 'value prop as string',
450
+ link: 'https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/introducing-attributes-and-editable-fields/',
451
+ } );
452
+
439
453
  value = childrenSource.toHTML( value );
440
454
  }
441
455
 
@@ -1,9 +1,14 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import classnames from 'classnames';
5
+
1
6
  /**
2
7
  * WordPress dependencies
3
8
  */
4
9
  import { useState } from '@wordpress/element';
5
10
  import { __ } from '@wordpress/i18n';
6
- import { __experimentalText as Text } from '@wordpress/components';
11
+ import { BaseControl } from '@wordpress/components';
7
12
 
8
13
  /**
9
14
  * Internal dependencies
@@ -68,8 +73,15 @@ export default function SpacingSizesControl( {
68
73
  };
69
74
 
70
75
  return (
71
- <fieldset role="region" className="component-spacing-sizes-control">
72
- <Text as="legend">{ label }</Text>
76
+ <fieldset
77
+ role="region"
78
+ className={ classnames( 'component-spacing-sizes-control', {
79
+ 'is-unlinked': ! isLinked,
80
+ } ) }
81
+ >
82
+ <BaseControl.VisualLabel as="legend">
83
+ { label }
84
+ </BaseControl.VisualLabel>
73
85
  { ! hasOneSide && (
74
86
  <LinkedButton onClick={ toggleLinked } isLinked={ isLinked } />
75
87
  ) }
@@ -9,12 +9,12 @@ import classnames from 'classnames';
9
9
  import { useState, useMemo } from '@wordpress/element';
10
10
  import { useSelect } from '@wordpress/data';
11
11
  import {
12
+ BaseControl,
12
13
  Button,
13
14
  RangeControl,
14
15
  CustomSelectControl,
15
16
  __experimentalUnitControl as UnitControl,
16
17
  __experimentalHStack as HStack,
17
- __experimentalText as Text,
18
18
  __experimentalUseCustomUnits as useCustomUnits,
19
19
  __experimentalParseQuantityAndUnitFromRawValue as parseQuantityAndUnitFromRawValue,
20
20
  } from '@wordpress/components';
@@ -167,21 +167,21 @@ export default function SpacingInputControl( {
167
167
  <>
168
168
  { side !== 'all' && (
169
169
  <HStack className="components-spacing-sizes-control__side-labels">
170
- <Text className="components-spacing-sizes-control__side-label">
170
+ <BaseControl.VisualLabel className="components-spacing-sizes-control__side-label">
171
171
  { LABELS[ side ] }
172
- </Text>
172
+ </BaseControl.VisualLabel>
173
173
 
174
174
  { showHint && (
175
- <Text className="components-spacing-sizes-control__hint-single">
175
+ <BaseControl.VisualLabel className="components-spacing-sizes-control__hint-single">
176
176
  { currentValueHint }
177
- </Text>
177
+ </BaseControl.VisualLabel>
178
178
  ) }
179
179
  </HStack>
180
180
  ) }
181
181
  { side === 'all' && showHint && (
182
- <Text className="components-spacing-sizes-control__hint-all">
182
+ <BaseControl.VisualLabel className="components-spacing-sizes-control__hint-all">
183
183
  { currentValueHint }
184
- </Text>
184
+ </BaseControl.VisualLabel>
185
185
  ) }
186
186
 
187
187
  { ! disableCustomSpacingSizes && (
@@ -256,6 +256,7 @@ export default function SpacingInputControl( {
256
256
  marks={ marks }
257
257
  label={ ariaLabel }
258
258
  hideLabelFromVision={ true }
259
+ __nextHasNoMarginBottom={ true }
259
260
  />
260
261
  ) }
261
262
  { ! showRangeControl && ! showCustomValueControl && (
@@ -1,7 +1,8 @@
1
1
  .tools-panel-item-spacing {
2
2
  display: grid;
3
3
  grid-template-columns: auto 1fr auto;
4
- grid-row-gap: $grid-unit-05;
4
+ align-items: center;
5
+ grid-template-rows: 25px auto;
5
6
  }
6
7
 
7
8
  .component-spacing-sizes-control {
@@ -17,21 +18,34 @@
17
18
  align-self: center;
18
19
  }
19
20
 
21
+ .components-base-control__label {
22
+ margin-bottom: 0;
23
+ height: $grid-unit-20;
24
+ }
25
+
20
26
  .components-spacing-sizes-control__side-labels {
21
27
  grid-column: 1 / 1;
22
- min-height: 30px;
23
28
  justify-content: left;
29
+ height: $grid-unit-20;
30
+ margin-top: $grid-unit-15;
31
+ }
32
+
33
+ .components-spacing-sizes-control__side-label {
34
+ grid-column: 1 / 1;
35
+ justify-self: left;
36
+ margin-bottom: 0;
24
37
  }
25
38
 
26
- .components-spacing-sizes-control__hint-single {
27
- margin-top: 0;
28
- margin-left: 0;
39
+ &.is-unlinked {
40
+ .components-range-control.components-spacing-sizes-control__range-control {
41
+ margin-top: $grid-unit-15;
42
+ }
29
43
  }
30
44
 
31
45
  .components-spacing-sizes-control__hint-single,
32
46
  .components-spacing-sizes-control__hint-all {
33
47
  color: $gray-700;
34
- font-size: 12px;
48
+ margin-bottom: 0;
35
49
  }
36
50
 
37
51
  .components-spacing-sizes-control__hint-all {
@@ -47,6 +61,11 @@
47
61
  grid-row: 1 / 1;
48
62
  justify-self: end;
49
63
  padding: 0;
64
+ &.is-small.has-icon {
65
+ padding: 0;
66
+ min-width: $icon-size;
67
+ height: $grid-unit-20;
68
+ }
50
69
  }
51
70
 
52
71
  .component-spacing-sizes-control__linked-button ~ .components-spacing-sizes-control__custom-toggle-all {
@@ -56,13 +75,11 @@
56
75
  .components-spacing-sizes-control__custom-toggle-single {
57
76
  grid-column: 3 / 3;
58
77
  justify-self: end;
59
- }
60
-
61
- .components-spacing-sizes-control__custom-toggle-all,
62
- .components-spacing-sizes-control__custom-toggle-single {
63
78
  &.is-small.has-icon {
64
79
  padding: 0;
65
80
  min-width: $icon-size;
81
+ height: $grid-unit-20;
82
+ margin-top: $grid-unit-15;
66
83
  }
67
84
  }
68
85
 
@@ -75,7 +92,6 @@
75
92
  .components-spacing-sizes-control__custom-value-range {
76
93
  grid-column: span 2;
77
94
  margin-left: $grid-unit-10;
78
- padding-right: $grid-unit-10;
79
95
  height: 30px;
80
96
  }
81
97
 
@@ -85,12 +101,7 @@
85
101
 
86
102
  .components-spacing-sizes-control__range-control {
87
103
  grid-column: span 3;
88
- padding-right: $grid-unit-10;
89
- height: 30px;
90
- }
91
-
92
- .components-range-control__wrapper {
93
- margin-bottom: 0;
104
+ height: 40px;
94
105
  }
95
106
 
96
107
  .components-range-control__mark {
@@ -112,13 +123,6 @@
112
123
  z-index: 3;
113
124
  }
114
125
 
115
- .components-spacing-sizes-control__side-label {
116
- margin-right: $grid-unit-05;
117
- grid-column: 1 / 1;
118
- justify-self: left;
119
- font-size: 12px;
120
- }
121
-
122
126
  .components-spacing-sizes-control__custom-select-control {
123
127
  grid-column: span 3;
124
128
  }
@@ -20,6 +20,7 @@ import './metadata';
20
20
  import './metadata-name';
21
21
 
22
22
  export { useCustomSides } from './dimensions';
23
+ export { useLayoutClasses, useLayoutStyles } from './layout';
23
24
  export { getBorderClassesAndStyles, useBorderProps } from './use-border-props';
24
25
  export { getColorClassesAndStyles, useColorProps } from './use-color-props';
25
26
  export { getSpacingClassesAndStyles } from './use-spacing-props';
@@ -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';