@wordpress/block-editor 8.0.12 → 8.0.13

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 (42) hide show
  1. package/build/components/block-tools/index.js +9 -0
  2. package/build/components/block-tools/index.js.map +1 -1
  3. package/build/components/gradients/use-gradient.js +4 -4
  4. package/build/components/gradients/use-gradient.js.map +1 -1
  5. package/build/hooks/color.js +6 -5
  6. package/build/hooks/color.js.map +1 -1
  7. package/build/hooks/layout.js +2 -1
  8. package/build/hooks/layout.js.map +1 -1
  9. package/build/hooks/style.js +2 -1
  10. package/build/hooks/style.js.map +1 -1
  11. package/build/layouts/flex.js +6 -2
  12. package/build/layouts/flex.js.map +1 -1
  13. package/build/layouts/flow.js +10 -6
  14. package/build/layouts/flow.js.map +1 -1
  15. package/build/store/selectors.js +25 -7
  16. package/build/store/selectors.js.map +1 -1
  17. package/build-module/components/block-tools/index.js +9 -0
  18. package/build-module/components/block-tools/index.js.map +1 -1
  19. package/build-module/components/gradients/use-gradient.js +4 -3
  20. package/build-module/components/gradients/use-gradient.js.map +1 -1
  21. package/build-module/hooks/color.js +6 -5
  22. package/build-module/hooks/color.js.map +1 -1
  23. package/build-module/hooks/layout.js +2 -1
  24. package/build-module/hooks/layout.js.map +1 -1
  25. package/build-module/hooks/style.js +2 -1
  26. package/build-module/hooks/style.js.map +1 -1
  27. package/build-module/layouts/flex.js +6 -2
  28. package/build-module/layouts/flex.js.map +1 -1
  29. package/build-module/layouts/flow.js +10 -6
  30. package/build-module/layouts/flow.js.map +1 -1
  31. package/build-module/store/selectors.js +24 -7
  32. package/build-module/store/selectors.js.map +1 -1
  33. package/package.json +3 -3
  34. package/src/components/block-tools/index.js +11 -0
  35. package/src/components/gradients/use-gradient.js +7 -7
  36. package/src/hooks/color.js +13 -14
  37. package/src/hooks/layout.js +1 -0
  38. package/src/hooks/style.js +2 -1
  39. package/src/hooks/test/style.js +0 -2
  40. package/src/layouts/flex.js +4 -6
  41. package/src/layouts/flow.js +8 -6
  42. package/src/store/selectors.js +37 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/block-editor",
3
- "version": "8.0.12",
3
+ "version": "8.0.13",
4
4
  "description": "Generic block editor.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -38,7 +38,7 @@
38
38
  "@wordpress/blob": "^3.2.2",
39
39
  "@wordpress/block-serialization-default-parser": "^4.2.3",
40
40
  "@wordpress/blocks": "^11.1.5",
41
- "@wordpress/components": "^19.1.6",
41
+ "@wordpress/components": "^19.2.0",
42
42
  "@wordpress/compose": "^5.0.7",
43
43
  "@wordpress/data": "^6.1.5",
44
44
  "@wordpress/deprecated": "^3.2.3",
@@ -75,5 +75,5 @@
75
75
  "publishConfig": {
76
76
  "access": "public"
77
77
  },
78
- "gitHead": "1081a28b2368fcebd9a14554fbd0e25eb33fbcb6"
78
+ "gitHead": "f70f4664ac641bd107481c5c67ee6f5556a0a381"
79
79
  }
@@ -95,6 +95,17 @@ export default function BlockTools( {
95
95
  } else if (
96
96
  isMatch( 'core/block-editor/delete-multi-selection', event )
97
97
  ) {
98
+ /**
99
+ * Check if the target element is a text area, input or
100
+ * event.defaultPrevented and return early. In all these
101
+ * cases backspace could be handled elsewhere.
102
+ */
103
+ if (
104
+ [ 'INPUT', 'TEXTAREA' ].includes( event.target.nodeName ) ||
105
+ event.defaultPrevented
106
+ ) {
107
+ return;
108
+ }
98
109
  const clientIds = getSelectedBlockClientIds();
99
110
  if ( clientIds.length > 1 ) {
100
111
  event.preventDefault();
@@ -59,22 +59,22 @@ export function getGradientSlugByValue( gradients, value ) {
59
59
  return gradient && gradient.slug;
60
60
  }
61
61
 
62
- const EMPTY_OBJECT = {};
63
-
64
62
  export function __experimentalUseGradient( {
65
63
  gradientAttribute = 'gradient',
66
64
  customGradientAttribute = 'customGradient',
67
65
  } = {} ) {
68
66
  const { clientId } = useBlockEditContext();
69
67
 
70
- const gradientsPerOrigin = useSetting( 'color.gradients' ) || EMPTY_OBJECT;
68
+ const userGradientPalette = useSetting( 'color.gradients.custom' );
69
+ const themeGradientPalette = useSetting( 'color.gradients.theme' );
70
+ const defaultGradientPalette = useSetting( 'color.gradients.default' );
71
71
  const allGradients = useMemo(
72
72
  () => [
73
- ...( gradientsPerOrigin?.custom || [] ),
74
- ...( gradientsPerOrigin?.theme || [] ),
75
- ...( gradientsPerOrigin?.default || [] ),
73
+ ...( userGradientPalette || [] ),
74
+ ...( themeGradientPalette || [] ),
75
+ ...( defaultGradientPalette || [] ),
76
76
  ],
77
- [ gradientsPerOrigin ]
77
+ [ userGradientPalette, themeGradientPalette, defaultGradientPalette ]
78
78
  );
79
79
  const { gradient, customGradient } = useSelect(
80
80
  ( select ) => {
@@ -32,8 +32,6 @@ import useSetting from '../components/use-setting';
32
32
 
33
33
  export const COLOR_SUPPORT_KEY = 'color';
34
34
 
35
- const EMPTY_OBJECT = {};
36
-
37
35
  const hasColorSupport = ( blockType ) => {
38
36
  const colorSupport = getBlockSupport( blockType, COLOR_SUPPORT_KEY );
39
37
  return (
@@ -232,7 +230,17 @@ export function ColorEdit( props ) {
232
230
  ],
233
231
  [ userPalette, themePalette, defaultPalette ]
234
232
  );
235
- const gradientsPerOrigin = useSetting( 'color.gradients' ) || EMPTY_OBJECT;
233
+ const userGradientPalette = useSetting( 'color.gradients.custom' );
234
+ const themeGradientPalette = useSetting( 'color.gradients.theme' );
235
+ const defaultGradientPalette = useSetting( 'color.gradients.default' );
236
+ const allGradients = useMemo(
237
+ () => [
238
+ ...( userGradientPalette || [] ),
239
+ ...( themeGradientPalette || [] ),
240
+ ...( defaultGradientPalette || [] ),
241
+ ],
242
+ [ userGradientPalette, themeGradientPalette, defaultGradientPalette ]
243
+ );
236
244
  const areCustomSolidsEnabled = useSetting( 'color.custom' );
237
245
  const areCustomGradientsEnabled = useSetting( 'color.customGradient' );
238
246
  const isBackgroundEnabled = useSetting( 'color.background' );
@@ -244,17 +252,8 @@ export function ColorEdit( props ) {
244
252
 
245
253
  const gradientsEnabled =
246
254
  areCustomGradientsEnabled ||
247
- ! gradientsPerOrigin?.theme ||
248
- gradientsPerOrigin?.theme?.length > 0;
249
-
250
- const allGradients = useMemo(
251
- () => [
252
- ...( gradientsPerOrigin?.custom || [] ),
253
- ...( gradientsPerOrigin?.theme || [] ),
254
- ...( gradientsPerOrigin?.default || [] ),
255
- ],
256
- [ gradientsPerOrigin ]
257
- );
255
+ ! themeGradientPalette ||
256
+ themeGradientPalette?.length > 0;
258
257
 
259
258
  // Shouldn't be needed but right now the ColorGradientsPanel
260
259
  // can trigger both onChangeColor and onChangeBackground
@@ -215,6 +215,7 @@ export const withLayoutStyles = createHigherOrderComponent(
215
215
  <LayoutStyle
216
216
  selector={ `.wp-container-${ id }` }
217
217
  layout={ usedLayout }
218
+ style={ attributes?.style }
218
219
  />,
219
220
  element
220
221
  ) }
@@ -74,6 +74,7 @@ function compileStyleValue( uncompiledValue ) {
74
74
  * @return {Object} Flattened CSS variables declaration.
75
75
  */
76
76
  export function getInlineStyles( styles = {} ) {
77
+ const ignoredStyles = [ 'spacing.blockGap' ];
77
78
  const output = {};
78
79
  Object.keys( STYLE_PROPERTY ).forEach( ( propKey ) => {
79
80
  const path = STYLE_PROPERTY[ propKey ].value;
@@ -93,7 +94,7 @@ export function getInlineStyles( styles = {} ) {
93
94
  output[ name ] = compileStyleValue( value );
94
95
  }
95
96
  } );
96
- } else {
97
+ } else if ( ! ignoredStyles.includes( path.join( '.' ) ) ) {
97
98
  output[ propKey ] = compileStyleValue( get( styles, path ) );
98
99
  }
99
100
  }
@@ -30,7 +30,6 @@ describe( 'getInlineStyles', () => {
30
30
  },
31
31
  } )
32
32
  ).toEqual( {
33
- '--wp--style--block-gap': '1em',
34
33
  backgroundColor: 'black',
35
34
  borderColor: '#21759b',
36
35
  borderRadius: '10px',
@@ -104,7 +103,6 @@ describe( 'getInlineStyles', () => {
104
103
  },
105
104
  } )
106
105
  ).toEqual( {
107
- '--wp--style--block-gap': '1em',
108
106
  margin: '10px',
109
107
  padding: '20px',
110
108
  } );
@@ -84,10 +84,12 @@ export default {
84
84
  </BlockControls>
85
85
  );
86
86
  },
87
- save: function FlexLayoutStyle( { selector, layout } ) {
87
+ save: function FlexLayoutStyle( { selector, layout, style } ) {
88
88
  const { orientation = 'horizontal' } = layout;
89
89
  const blockGapSupport = useSetting( 'spacing.blockGap' );
90
90
  const hasBlockGapStylesSupport = blockGapSupport !== null;
91
+ const blockGapValue =
92
+ style?.spacing?.blockGap ?? 'var( --wp--style--block-gap, 0.5em )';
91
93
  const justifyContent =
92
94
  justifyContentMap[ layout.justifyContent ] ||
93
95
  justifyContentMap.left;
@@ -110,11 +112,7 @@ export default {
110
112
  <style>{ `
111
113
  ${ appendSelectors( selector ) } {
112
114
  display: flex;
113
- gap: ${
114
- hasBlockGapStylesSupport
115
- ? 'var( --wp--style--block-gap, 0.5em )'
116
- : '0.5em'
117
- };
115
+ gap: ${ hasBlockGapStylesSupport ? blockGapValue : '0.5em' };
118
116
  flex-wrap: ${ flexWrap };
119
117
  ${ orientation === 'horizontal' ? rowOrientation : columnOrientation }
120
118
  }
@@ -105,12 +105,14 @@ export default {
105
105
  toolBarControls: function DefaultLayoutToolbarControls() {
106
106
  return null;
107
107
  },
108
- save: function DefaultLayoutStyle( { selector, layout = {} } ) {
108
+ save: function DefaultLayoutStyle( { selector, layout = {}, style } ) {
109
109
  const { contentSize, wideSize } = layout;
110
110
  const blockGapSupport = useSetting( 'spacing.blockGap' );
111
111
  const hasBlockGapStylesSupport = blockGapSupport !== null;
112
+ const blockGapValue =
113
+ style?.spacing?.blockGap ?? 'var( --wp--style--block-gap )';
112
114
 
113
- let style =
115
+ let output =
114
116
  !! contentSize || !! wideSize
115
117
  ? `
116
118
  ${ appendSelectors( selector, '> *' ) } {
@@ -129,7 +131,7 @@ export default {
129
131
  `
130
132
  : '';
131
133
 
132
- style += `
134
+ output += `
133
135
  ${ appendSelectors( selector, '> [data-align="left"]' ) } {
134
136
  float: left;
135
137
  margin-right: 2em;
@@ -143,18 +145,18 @@ export default {
143
145
  `;
144
146
 
145
147
  if ( hasBlockGapStylesSupport ) {
146
- style += `
148
+ output += `
147
149
  ${ appendSelectors( selector, '> *' ) } {
148
150
  margin-top: 0;
149
151
  margin-bottom: 0;
150
152
  }
151
153
  ${ appendSelectors( selector, '> * + *' ) } {
152
- margin-top: var( --wp--style--block-gap );
154
+ margin-top: ${ blockGapValue };
153
155
  }
154
156
  `;
155
157
  }
156
158
 
157
- return <style>{ style }</style>;
159
+ return <style>{ output }</style>;
158
160
  },
159
161
  getOrientation() {
160
162
  return 'vertical';
@@ -30,6 +30,7 @@ import {
30
30
  parse,
31
31
  } from '@wordpress/blocks';
32
32
  import { Platform } from '@wordpress/element';
33
+ import { applyFilters } from '@wordpress/hooks';
33
34
  import { symbol } from '@wordpress/icons';
34
35
 
35
36
  /**
@@ -826,6 +827,7 @@ export const isAncestorMultiSelected = createSelector(
826
827
  state.selection.selectionEnd.clientId,
827
828
  ]
828
829
  );
830
+
829
831
  /**
830
832
  * Returns the client ID of the block which begins the multi-selection set, or
831
833
  * null if there is no multi-selection.
@@ -1259,15 +1261,43 @@ const canInsertBlockTypeUnmemoized = (
1259
1261
  parentName
1260
1262
  );
1261
1263
 
1262
- if ( hasParentAllowedBlock !== null && hasBlockAllowedParent !== null ) {
1263
- return hasParentAllowedBlock || hasBlockAllowedParent;
1264
- } else if ( hasParentAllowedBlock !== null ) {
1265
- return hasParentAllowedBlock;
1266
- } else if ( hasBlockAllowedParent !== null ) {
1267
- return hasBlockAllowedParent;
1264
+ const canInsert =
1265
+ ( hasParentAllowedBlock === null && hasBlockAllowedParent === null ) ||
1266
+ hasParentAllowedBlock === true ||
1267
+ hasBlockAllowedParent === true;
1268
+
1269
+ if ( ! canInsert ) {
1270
+ return canInsert;
1268
1271
  }
1269
1272
 
1270
- return true;
1273
+ /**
1274
+ * This filter is an ad-hoc solution to prevent adding template parts inside post content.
1275
+ * Conceptually, having a filter inside a selector is bad pattern so this code will be
1276
+ * replaced by a declarative API that doesn't the following drawbacks:
1277
+ *
1278
+ * Filters are not reactive: Upon switching between "template mode" and non "template mode",
1279
+ * the filter and selector won't necessarily be executed again. For now, it doesn't matter much
1280
+ * because you can't switch between the two modes while the inserter stays open.
1281
+ *
1282
+ * Filters are global: Once they're defined, they will affect all editor instances and all registries.
1283
+ * An ideal API would only affect specific editor instances.
1284
+ */
1285
+ return applyFilters(
1286
+ 'blockEditor.__unstableCanInsertBlockType',
1287
+ canInsert,
1288
+ blockType,
1289
+ rootClientId,
1290
+ {
1291
+ // Pass bound selectors of the current registry. If we're in a nested
1292
+ // context, the data will differ from the one selected from the root
1293
+ // registry.
1294
+ getBlock: getBlock.bind( null, state ),
1295
+ getBlockParentsByBlockName: getBlockParentsByBlockName.bind(
1296
+ null,
1297
+ state
1298
+ ),
1299
+ }
1300
+ );
1271
1301
  };
1272
1302
 
1273
1303
  /**