@wordpress/block-editor 8.5.7 → 8.5.10

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 (44) hide show
  1. package/build/components/block-styles/index.js +3 -6
  2. package/build/components/block-styles/index.js.map +1 -1
  3. package/build/components/block-variation-transforms/index.js +5 -0
  4. package/build/components/block-variation-transforms/index.js.map +1 -1
  5. package/build/components/media-placeholder/index.js +0 -2
  6. package/build/components/media-placeholder/index.js.map +1 -1
  7. package/build/components/media-replace-flow/index.js +0 -2
  8. package/build/components/media-replace-flow/index.js.map +1 -1
  9. package/build/components/rich-text/use-paste-handler.js +20 -5
  10. package/build/components/rich-text/use-paste-handler.js.map +1 -1
  11. package/build/hooks/dimensions.js +14 -4
  12. package/build/hooks/dimensions.js.map +1 -1
  13. package/build/hooks/layout.js +38 -1
  14. package/build/hooks/layout.js.map +1 -1
  15. package/build/layouts/flex.js +5 -2
  16. package/build/layouts/flex.js.map +1 -1
  17. package/build-module/components/block-styles/index.js +4 -7
  18. package/build-module/components/block-styles/index.js.map +1 -1
  19. package/build-module/components/block-variation-transforms/index.js +5 -0
  20. package/build-module/components/block-variation-transforms/index.js.map +1 -1
  21. package/build-module/components/media-placeholder/index.js +0 -2
  22. package/build-module/components/media-placeholder/index.js.map +1 -1
  23. package/build-module/components/media-replace-flow/index.js +0 -2
  24. package/build-module/components/media-replace-flow/index.js.map +1 -1
  25. package/build-module/components/rich-text/use-paste-handler.js +20 -5
  26. package/build-module/components/rich-text/use-paste-handler.js.map +1 -1
  27. package/build-module/hooks/dimensions.js +14 -4
  28. package/build-module/hooks/dimensions.js.map +1 -1
  29. package/build-module/hooks/layout.js +39 -2
  30. package/build-module/hooks/layout.js.map +1 -1
  31. package/build-module/layouts/flex.js +4 -2
  32. package/build-module/layouts/flex.js.map +1 -1
  33. package/build-style/style-rtl.css +6 -0
  34. package/build-style/style.css +6 -0
  35. package/package.json +4 -4
  36. package/src/components/block-styles/index.js +4 -7
  37. package/src/components/block-styles/style.scss +10 -0
  38. package/src/components/block-variation-transforms/index.js +3 -0
  39. package/src/components/media-placeholder/index.js +0 -2
  40. package/src/components/media-replace-flow/index.js +0 -2
  41. package/src/components/rich-text/use-paste-handler.js +17 -5
  42. package/src/hooks/dimensions.js +11 -3
  43. package/src/hooks/layout.js +54 -4
  44. package/src/layouts/flex.js +11 -3
@@ -254,17 +254,29 @@ export function usePasteHandler( props ) {
254
254
  }
255
255
 
256
256
  /**
257
- * Normalizes a given string of HTML to remove the Windows specific "Fragment" comments
258
- * and any preceeding and trailing whitespace.
257
+ * Normalizes a given string of HTML to remove the Windows-specific "Fragment"
258
+ * comments and any preceeding and trailing content.
259
259
  *
260
260
  * @param {string} html the html to be normalized
261
261
  * @return {string} the normalized html
262
262
  */
263
263
  function removeWindowsFragments( html ) {
264
- const startReg = /.*<!--StartFragment-->/s;
265
- const endReg = /<!--EndFragment-->.*/s;
264
+ const startStr = '<!--StartFragment-->';
265
+ const startIdx = html.indexOf( startStr );
266
+ if ( startIdx > -1 ) {
267
+ html = html.substring( startIdx + startStr.length );
268
+ } else {
269
+ // No point looking for EndFragment
270
+ return html;
271
+ }
272
+
273
+ const endStr = '<!--EndFragment-->';
274
+ const endIdx = html.indexOf( endStr );
275
+ if ( endIdx > -1 ) {
276
+ html = html.substring( 0, endIdx );
277
+ }
266
278
 
267
- return html.replace( startReg, '' ).replace( endReg, '' );
279
+ return html;
268
280
  }
269
281
 
270
282
  /**
@@ -147,7 +147,7 @@ const useIsDimensionsDisabled = ( props = {} ) => {
147
147
  };
148
148
 
149
149
  /**
150
- * Custom hook to retrieve which padding/margin is supported
150
+ * Custom hook to retrieve which padding/margin/blockGap is supported
151
151
  * e.g. top, right, bottom or left.
152
152
  *
153
153
  * Sides are opted into by default. It is only if a specific side is set to
@@ -156,7 +156,7 @@ const useIsDimensionsDisabled = ( props = {} ) => {
156
156
  * @param {string} blockName Block name.
157
157
  * @param {string} feature The feature custom sides relate to e.g. padding or margins.
158
158
  *
159
- * @return {Object} Sides supporting custom margin.
159
+ * @return {?string[]} Strings representing the custom sides available.
160
160
  */
161
161
  export function useCustomSides( blockName, feature ) {
162
162
  const support = getBlockSupport( blockName, SPACING_SUPPORT_KEY );
@@ -166,7 +166,15 @@ export function useCustomSides( blockName, feature ) {
166
166
  return;
167
167
  }
168
168
 
169
- return support[ feature ];
169
+ // Return if the setting is an array of sides (e.g. `[ 'top', 'bottom' ]`).
170
+ if ( Array.isArray( support[ feature ] ) ) {
171
+ return support[ feature ];
172
+ }
173
+
174
+ // Finally, attempt to return `.sides` if the setting is an object.
175
+ if ( support[ feature ]?.sides ) {
176
+ return support[ feature ].sides;
177
+ }
170
178
  }
171
179
 
172
180
  /**
@@ -2,7 +2,7 @@
2
2
  * External dependencies
3
3
  */
4
4
  import classnames from 'classnames';
5
- import { has } from 'lodash';
5
+ import { has, kebabCase } from 'lodash';
6
6
 
7
7
  /**
8
8
  * WordPress dependencies
@@ -32,6 +32,49 @@ import { getLayoutType, getLayoutTypes } from '../layouts';
32
32
 
33
33
  const layoutBlockSupportKey = '__experimentalLayout';
34
34
 
35
+ /**
36
+ * Generates the utility classnames for the given blocks layout attributes.
37
+ * This method was primarily added to reintroduce classnames that were removed
38
+ * in the 5.9 release (https://github.com/WordPress/gutenberg/issues/38719), rather
39
+ * than providing an extensive list of all possible layout classes. The plan is to
40
+ * have the style engine generate a more extensive list of utility classnames which
41
+ * will then replace this method.
42
+ *
43
+ * @param { Array } attributes Array of block attributes.
44
+ *
45
+ * @return { Array } Array of CSS classname strings.
46
+ */
47
+ function getLayoutClasses( attributes ) {
48
+ const layoutClassnames = [];
49
+
50
+ if ( ! attributes.layout ) {
51
+ return layoutClassnames;
52
+ }
53
+
54
+ if ( attributes?.layout?.orientation ) {
55
+ layoutClassnames.push(
56
+ `is-${ kebabCase( attributes.layout.orientation ) }`
57
+ );
58
+ }
59
+
60
+ if ( attributes?.layout?.justifyContent ) {
61
+ layoutClassnames.push(
62
+ `is-content-justification-${ kebabCase(
63
+ attributes.layout.justifyContent
64
+ ) }`
65
+ );
66
+ }
67
+
68
+ if (
69
+ attributes?.layout?.flexWrap &&
70
+ attributes.layout.flexWrap === 'nowrap'
71
+ ) {
72
+ layoutClassnames.push( 'is-nowrap' );
73
+ }
74
+
75
+ return layoutClassnames;
76
+ }
77
+
35
78
  function LayoutPanel( { setAttributes, attributes, name: blockName } ) {
36
79
  const { layout } = attributes;
37
80
  const defaultThemeLayout = useSetting( 'layout' );
@@ -212,9 +255,16 @@ export const withLayoutStyles = createHigherOrderComponent(
212
255
  const usedLayout = layout?.inherit
213
256
  ? defaultThemeLayout
214
257
  : layout || defaultBlockLayout || {};
215
- const className = classnames( props?.className, {
216
- [ `wp-container-${ id }` ]: shouldRenderLayoutStyles,
217
- } );
258
+ const layoutClasses = shouldRenderLayoutStyles
259
+ ? getLayoutClasses( attributes )
260
+ : null;
261
+ const className = classnames(
262
+ props?.className,
263
+ {
264
+ [ `wp-container-${ id }` ]: shouldRenderLayoutStyles,
265
+ },
266
+ layoutClasses
267
+ );
218
268
 
219
269
  return (
220
270
  <>
@@ -11,6 +11,7 @@ import {
11
11
  arrowDown,
12
12
  } from '@wordpress/icons';
13
13
  import { Button, ToggleControl, Flex, FlexItem } from '@wordpress/components';
14
+ import { getBlockSupport } from '@wordpress/blocks';
14
15
 
15
16
  /**
16
17
  * Internal dependencies
@@ -109,14 +110,21 @@ export default {
109
110
  save: function FlexLayoutStyle( { selector, layout, style, blockName } ) {
110
111
  const { orientation = 'horizontal' } = layout;
111
112
  const blockGapSupport = useSetting( 'spacing.blockGap' );
113
+ const fallbackValue =
114
+ getBlockSupport( blockName, [
115
+ 'spacing',
116
+ 'blockGap',
117
+ '__experimentalDefault',
118
+ ] ) || '0.5em';
119
+
112
120
  const hasBlockGapStylesSupport = blockGapSupport !== null;
113
121
  // If a block's block.json skips serialization for spacing or spacing.blockGap,
114
122
  // don't apply the user-defined value to the styles.
115
123
  const blockGapValue =
116
124
  style?.spacing?.blockGap &&
117
125
  ! shouldSkipSerialization( blockName, 'spacing', 'blockGap' )
118
- ? getGapCSSValue( style?.spacing?.blockGap, '0.5em' )
119
- : 'var( --wp--style--block-gap, 0.5em )';
126
+ ? getGapCSSValue( style?.spacing?.blockGap, fallbackValue )
127
+ : `var( --wp--style--block-gap, ${ fallbackValue } )`;
120
128
  const justifyContent =
121
129
  justifyContentMap[ layout.justifyContent ] ||
122
130
  justifyContentMap.left;
@@ -143,7 +151,7 @@ export default {
143
151
  ${ appendSelectors( selector ) } {
144
152
  display: flex;
145
153
  flex-wrap: ${ flexWrap };
146
- gap: ${ hasBlockGapStylesSupport ? blockGapValue : '0.5em' };
154
+ gap: ${ hasBlockGapStylesSupport ? blockGapValue : fallbackValue };
147
155
  ${ orientation === 'horizontal' ? rowOrientation : columnOrientation }
148
156
  }
149
157