@wordpress/block-editor 12.19.3 → 12.20.0

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 (127) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/block-canvas/index.js +2 -0
  3. package/build/components/block-canvas/index.js.map +1 -1
  4. package/build/components/block-heading-level-dropdown/index.js +14 -17
  5. package/build/components/block-heading-level-dropdown/index.js.map +1 -1
  6. package/build/components/block-inspector/index.js +0 -3
  7. package/build/components/block-inspector/index.js.map +1 -1
  8. package/build/components/block-list/index.js +9 -9
  9. package/build/components/block-list/index.js.map +1 -1
  10. package/build/components/block-preview/index.js +4 -0
  11. package/build/components/block-preview/index.js.map +1 -1
  12. package/build/components/block-settings-menu/block-parent-selector-menu-item.js +54 -0
  13. package/build/components/block-settings-menu/block-parent-selector-menu-item.js.map +1 -0
  14. package/build/components/block-settings-menu/block-settings-dropdown.js +9 -37
  15. package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  16. package/build/components/child-layout-control/index.js +37 -5
  17. package/build/components/child-layout-control/index.js.map +1 -1
  18. package/build/components/date-format-picker/index.js +0 -1
  19. package/build/components/date-format-picker/index.js.map +1 -1
  20. package/build/components/font-appearance-control/index.js +1 -2
  21. package/build/components/font-appearance-control/index.js.map +1 -1
  22. package/build/components/global-styles/dimensions-panel.js +30 -19
  23. package/build/components/global-styles/dimensions-panel.js.map +1 -1
  24. package/build/components/inspector-controls-tabs/styles-tab.js +0 -4
  25. package/build/components/inspector-controls-tabs/styles-tab.js.map +1 -1
  26. package/build/components/observe-typing/index.js +5 -10
  27. package/build/components/observe-typing/index.js.map +1 -1
  28. package/build/components/rich-text/format-toolbar-container.js +1 -31
  29. package/build/components/rich-text/format-toolbar-container.js.map +1 -1
  30. package/build/components/rich-text/index.js +1 -2
  31. package/build/components/rich-text/index.js.map +1 -1
  32. package/build/components/skip-to-selected-block/index.js +7 -14
  33. package/build/components/skip-to-selected-block/index.js.map +1 -1
  34. package/build/components/spacing-sizes-control/input-controls/spacing-input-control.js +0 -1
  35. package/build/components/spacing-sizes-control/input-controls/spacing-input-control.js.map +1 -1
  36. package/build/components/url-input/index.js +5 -8
  37. package/build/components/url-input/index.js.map +1 -1
  38. package/build/hooks/layout-child.js +50 -1
  39. package/build/hooks/layout-child.js.map +1 -1
  40. package/build/hooks/position.js +0 -1
  41. package/build/hooks/position.js.map +1 -1
  42. package/build/layouts/grid.js +105 -12
  43. package/build/layouts/grid.js.map +1 -1
  44. package/build/store/actions.js +2 -30
  45. package/build/store/actions.js.map +1 -1
  46. package/build-module/components/block-canvas/index.js +2 -0
  47. package/build-module/components/block-canvas/index.js.map +1 -1
  48. package/build-module/components/block-heading-level-dropdown/index.js +14 -17
  49. package/build-module/components/block-heading-level-dropdown/index.js.map +1 -1
  50. package/build-module/components/block-inspector/index.js +1 -4
  51. package/build-module/components/block-inspector/index.js.map +1 -1
  52. package/build-module/components/block-list/index.js +9 -9
  53. package/build-module/components/block-list/index.js.map +1 -1
  54. package/build-module/components/block-preview/index.js +4 -0
  55. package/build-module/components/block-preview/index.js.map +1 -1
  56. package/build-module/components/block-settings-menu/block-parent-selector-menu-item.js +46 -0
  57. package/build-module/components/block-settings-menu/block-parent-selector-menu-item.js.map +1 -0
  58. package/build-module/components/block-settings-menu/block-settings-dropdown.js +12 -40
  59. package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  60. package/build-module/components/child-layout-control/index.js +38 -6
  61. package/build-module/components/child-layout-control/index.js.map +1 -1
  62. package/build-module/components/date-format-picker/index.js +0 -1
  63. package/build-module/components/date-format-picker/index.js.map +1 -1
  64. package/build-module/components/font-appearance-control/index.js +1 -2
  65. package/build-module/components/font-appearance-control/index.js.map +1 -1
  66. package/build-module/components/global-styles/dimensions-panel.js +30 -19
  67. package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
  68. package/build-module/components/inspector-controls-tabs/styles-tab.js +0 -4
  69. package/build-module/components/inspector-controls-tabs/styles-tab.js.map +1 -1
  70. package/build-module/components/observe-typing/index.js +5 -10
  71. package/build-module/components/observe-typing/index.js.map +1 -1
  72. package/build-module/components/rich-text/format-toolbar-container.js +1 -31
  73. package/build-module/components/rich-text/format-toolbar-container.js.map +1 -1
  74. package/build-module/components/rich-text/index.js +1 -2
  75. package/build-module/components/rich-text/index.js.map +1 -1
  76. package/build-module/components/skip-to-selected-block/index.js +8 -14
  77. package/build-module/components/skip-to-selected-block/index.js.map +1 -1
  78. package/build-module/components/spacing-sizes-control/input-controls/spacing-input-control.js +0 -1
  79. package/build-module/components/spacing-sizes-control/input-controls/spacing-input-control.js.map +1 -1
  80. package/build-module/components/url-input/index.js +5 -8
  81. package/build-module/components/url-input/index.js.map +1 -1
  82. package/build-module/hooks/layout-child.js +50 -1
  83. package/build-module/hooks/layout-child.js.map +1 -1
  84. package/build-module/hooks/position.js +0 -1
  85. package/build-module/hooks/position.js.map +1 -1
  86. package/build-module/layouts/grid.js +107 -14
  87. package/build-module/layouts/grid.js.map +1 -1
  88. package/build-module/store/actions.js +2 -30
  89. package/build-module/store/actions.js.map +1 -1
  90. package/build-style/style-rtl.css +12 -17
  91. package/build-style/style.css +12 -17
  92. package/package.json +31 -32
  93. package/src/components/block-canvas/index.js +2 -0
  94. package/src/components/block-heading-level-dropdown/index.js +17 -25
  95. package/src/components/block-inspector/index.js +0 -11
  96. package/src/components/block-list/index.js +55 -55
  97. package/src/components/block-preview/index.js +6 -1
  98. package/src/components/block-settings-menu/block-parent-selector-menu-item.js +50 -0
  99. package/src/components/block-settings-menu/block-settings-dropdown.js +9 -50
  100. package/src/components/block-styles/style.scss +0 -4
  101. package/src/components/block-toolbar/style.scss +11 -6
  102. package/src/components/child-layout-control/index.js +85 -44
  103. package/src/components/date-format-picker/index.js +0 -1
  104. package/src/components/font-appearance-control/index.js +0 -1
  105. package/src/components/global-styles/dimensions-panel.js +36 -24
  106. package/src/components/global-styles/test/use-global-styles-output.js +3 -2
  107. package/src/components/inspector-controls-tabs/styles-tab.js +0 -7
  108. package/src/components/observe-typing/index.js +7 -10
  109. package/src/components/rich-text/format-toolbar-container.js +1 -48
  110. package/src/components/rich-text/index.js +0 -1
  111. package/src/components/skip-to-selected-block/index.js +10 -13
  112. package/src/components/spacing-sizes-control/input-controls/spacing-input-control.js +0 -1
  113. package/src/components/url-input/index.js +6 -15
  114. package/src/hooks/anchor.scss +1 -1
  115. package/src/hooks/layout-child.js +53 -1
  116. package/src/hooks/position.js +0 -1
  117. package/src/layouts/grid.js +131 -52
  118. package/src/layouts/test/grid.js +16 -2
  119. package/src/store/actions.js +2 -38
  120. package/src/store/test/actions.js +0 -101
  121. package/src/style.scss +0 -1
  122. package/build/components/default-style-picker/index.js +0 -70
  123. package/build/components/default-style-picker/index.js.map +0 -1
  124. package/build-module/components/default-style-picker/index.js +0 -63
  125. package/build-module/components/default-style-picker/index.js.map +0 -1
  126. package/src/components/block-settings-menu/style.scss +0 -3
  127. package/src/components/default-style-picker/index.js +0 -70
@@ -2,7 +2,6 @@
2
2
  * External dependencies
3
3
  */
4
4
  import classnames from 'classnames';
5
- import scrollIntoView from 'dom-scroll-into-view';
6
5
 
7
6
  /**
8
7
  * WordPress dependencies
@@ -83,21 +82,13 @@ class URLInput extends Component {
83
82
  if (
84
83
  showSuggestions &&
85
84
  selectedSuggestion !== null &&
86
- this.suggestionNodes[ selectedSuggestion ] &&
87
- ! this.scrollingIntoView
85
+ this.suggestionNodes[ selectedSuggestion ]
88
86
  ) {
89
- this.scrollingIntoView = true;
90
- scrollIntoView(
91
- this.suggestionNodes[ selectedSuggestion ],
92
- this.autocompleteRef.current,
93
- {
94
- onlyScrollIfNeeded: true,
95
- }
96
- );
97
-
98
- this.props.setTimeout( () => {
99
- this.scrollingIntoView = false;
100
- }, 100 );
87
+ this.suggestionNodes[ selectedSuggestion ].scrollIntoView( {
88
+ behavior: 'instant',
89
+ block: 'nearest',
90
+ inline: 'nearest',
91
+ } );
101
92
  }
102
93
 
103
94
  // Update suggestions when the value changes.
@@ -1,4 +1,4 @@
1
1
  .html-anchor-control .components-external-link {
2
- display: block;
2
+ display: inline-block;
3
3
  margin-top: $grid-unit-10;
4
4
  }
@@ -9,13 +9,16 @@ import { useSelect } from '@wordpress/data';
9
9
  */
10
10
  import { store as blockEditorStore } from '../store';
11
11
  import { useStyleOverride } from './utils';
12
+ import { useLayout } from '../components/block-list/layout';
12
13
 
13
14
  function useBlockPropsChildLayoutStyles( { style } ) {
14
15
  const shouldRenderChildLayoutStyles = useSelect( ( select ) => {
15
16
  return ! select( blockEditorStore ).getSettings().disableLayoutStyles;
16
17
  } );
17
18
  const layout = style?.layout ?? {};
18
- const { selfStretch, flexSize } = layout;
19
+ const { selfStretch, flexSize, columnSpan, rowSpan } = layout;
20
+ const parentLayout = useLayout() || {};
21
+ const { columnCount, minimumColumnWidth } = parentLayout;
19
22
  const id = useInstanceId( useBlockPropsChildLayoutStyles );
20
23
  const selector = `.wp-container-content-${ id }`;
21
24
 
@@ -30,6 +33,55 @@ function useBlockPropsChildLayoutStyles( { style } ) {
30
33
  css = `${ selector } {
31
34
  flex-grow: 1;
32
35
  }`;
36
+ } else if ( columnSpan ) {
37
+ css = `${ selector } {
38
+ grid-column: span ${ columnSpan };
39
+ }`;
40
+ }
41
+ /**
42
+ * If minimumColumnWidth is set on the parent, or if no
43
+ * columnCount is set, the grid is responsive so a
44
+ * container query is needed for the span to resize.
45
+ */
46
+ if ( columnSpan && ( minimumColumnWidth || ! columnCount ) ) {
47
+ // Calculate the container query value.
48
+ const columnSpanNumber = parseInt( columnSpan );
49
+ let parentColumnValue = parseFloat( minimumColumnWidth );
50
+ /**
51
+ * 12rem is the default minimumColumnWidth value.
52
+ * If parentColumnValue is not a number, default to 12.
53
+ */
54
+ if ( isNaN( parentColumnValue ) ) {
55
+ parentColumnValue = 12;
56
+ }
57
+
58
+ let parentColumnUnit = minimumColumnWidth?.replace(
59
+ parentColumnValue,
60
+ ''
61
+ );
62
+ /**
63
+ * Check that parent column unit is either 'px', 'rem' or 'em'.
64
+ * If not, default to 'rem'.
65
+ */
66
+ if ( ! [ 'px', 'rem', 'em' ].includes( parentColumnUnit ) ) {
67
+ parentColumnUnit = 'rem';
68
+ }
69
+
70
+ const defaultGapValue = parentColumnUnit === 'px' ? 24 : 1.5;
71
+ const containerQueryValue =
72
+ columnSpanNumber * parentColumnValue +
73
+ ( columnSpanNumber - 1 ) * defaultGapValue;
74
+
75
+ css += `@container (max-width: ${ containerQueryValue }${ parentColumnUnit }) {
76
+ ${ selector } {
77
+ grid-column: 1 / -1;
78
+ }
79
+ }`;
80
+ }
81
+ if ( rowSpan ) {
82
+ css += `${ selector } {
83
+ grid-row: span ${ rowSpan };
84
+ }`;
33
85
  }
34
86
  }
35
87
 
@@ -288,7 +288,6 @@ export function PositionPanelPure( {
288
288
  help={ stickyHelpText }
289
289
  >
290
290
  <CustomSelectControl
291
- __nextUnconstrainedWidth
292
291
  __next40pxDefaultSize
293
292
  className="block-editor-hooks__position-selection__select-control"
294
293
  label={ __( 'Position' ) }
@@ -8,9 +8,13 @@ import {
8
8
  Flex,
9
9
  FlexItem,
10
10
  RangeControl,
11
+ __experimentalNumberControl as NumberControl,
12
+ __experimentalToggleGroupControl as ToggleGroupControl,
13
+ __experimentalToggleGroupControlOption as ToggleGroupControlOption,
11
14
  __experimentalUnitControl as UnitControl,
12
15
  __experimentalParseQuantityAndUnitFromRawValue as parseQuantityAndUnitFromRawValue,
13
16
  } from '@wordpress/components';
17
+ import { useState } from '@wordpress/element';
14
18
 
15
19
  /**
16
20
  * Internal dependencies
@@ -51,6 +55,12 @@ const RANGE_CONTROL_MAX_VALUES = {
51
55
  dvmax: 100,
52
56
  };
53
57
 
58
+ const units = [
59
+ { value: 'px', label: 'px', default: 0 },
60
+ { value: 'rem', label: 'rem', default: 0 },
61
+ { value: 'em', label: 'em', default: 0 },
62
+ ];
63
+
54
64
  export default {
55
65
  name: 'grid',
56
66
  label: __( 'Grid' ),
@@ -58,13 +68,24 @@ export default {
58
68
  layout = {},
59
69
  onChange,
60
70
  } ) {
61
- return layout?.columnCount ? (
62
- <GridLayoutColumnsControl layout={ layout } onChange={ onChange } />
63
- ) : (
64
- <GridLayoutMinimumWidthControl
65
- layout={ layout }
66
- onChange={ onChange }
67
- />
71
+ return (
72
+ <>
73
+ <GridLayoutTypeControl
74
+ layout={ layout }
75
+ onChange={ onChange }
76
+ />
77
+ { layout?.columnCount ? (
78
+ <GridLayoutColumnsControl
79
+ layout={ layout }
80
+ onChange={ onChange }
81
+ />
82
+ ) : (
83
+ <GridLayoutMinimumWidthControl
84
+ layout={ layout }
85
+ onChange={ onChange }
86
+ />
87
+ ) }
88
+ </>
68
89
  );
69
90
  },
70
91
  toolBarControls: function DefaultLayoutToolbarControls() {
@@ -97,7 +118,8 @@ export default {
97
118
  );
98
119
  } else if ( minimumColumnWidth ) {
99
120
  rules.push(
100
- `grid-template-columns: repeat(auto-fill, minmax(min(${ minimumColumnWidth }, 100%), 1fr))`
121
+ `grid-template-columns: repeat(auto-fill, minmax(min(${ minimumColumnWidth }, 100%), 1fr))`,
122
+ `container-type: inline-size`
101
123
  );
102
124
  }
103
125
 
@@ -152,38 +174,6 @@ function GridLayoutMinimumWidthControl( { layout, onChange } ) {
152
174
  } else if ( [ 'em', 'rem' ].includes( unit ) && newUnit === 'px' ) {
153
175
  // Convert to pixel value assuming a root size of 16px.
154
176
  newValue = Math.round( quantity * 16 ) + newUnit;
155
- } else if (
156
- [
157
- 'vh',
158
- 'vw',
159
- '%',
160
- 'svw',
161
- 'lvw',
162
- 'dvw',
163
- 'svh',
164
- 'lvh',
165
- 'dvh',
166
- 'vi',
167
- 'svi',
168
- 'lvi',
169
- 'dvi',
170
- 'vb',
171
- 'svb',
172
- 'lvb',
173
- 'dvb',
174
- 'vmin',
175
- 'svmin',
176
- 'lvmin',
177
- 'dvmin',
178
- 'vmax',
179
- 'svmax',
180
- 'lvmax',
181
- 'dvmax',
182
- ].includes( newUnit ) &&
183
- quantity > 100
184
- ) {
185
- // When converting to `%` or viewport-relative units, cap the new value at 100.
186
- newValue = 100 + newUnit;
187
177
  }
188
178
 
189
179
  onChange( {
@@ -209,7 +199,10 @@ function GridLayoutMinimumWidthControl( { layout, onChange } ) {
209
199
  } }
210
200
  onUnitChange={ handleUnitChange }
211
201
  value={ value }
202
+ units={ units }
212
203
  min={ 0 }
204
+ label={ __( 'Minimum column width' ) }
205
+ hideLabelFromVision
213
206
  />
214
207
  </FlexItem>
215
208
  <FlexItem isBlock>
@@ -219,6 +212,8 @@ function GridLayoutMinimumWidthControl( { layout, onChange } ) {
219
212
  min={ 0 }
220
213
  max={ RANGE_CONTROL_MAX_VALUES[ unit ] || 600 }
221
214
  withInputField={ false }
215
+ label={ __( 'Minimum column width' ) }
216
+ hideLabelFromVision
222
217
  />
223
218
  </FlexItem>
224
219
  </Flex>
@@ -231,17 +226,101 @@ function GridLayoutColumnsControl( { layout, onChange } ) {
231
226
  const { columnCount = 3 } = layout;
232
227
 
233
228
  return (
234
- <RangeControl
235
- label={ __( 'Columns' ) }
236
- value={ columnCount }
237
- onChange={ ( value ) =>
238
- onChange( {
239
- ...layout,
240
- columnCount: value,
241
- } )
242
- }
243
- min={ 1 }
244
- max={ 6 }
245
- />
229
+ <fieldset>
230
+ <BaseControl.VisualLabel as="legend">
231
+ { __( 'Columns' ) }
232
+ </BaseControl.VisualLabel>
233
+ <Flex gap={ 4 }>
234
+ <FlexItem isBlock>
235
+ <NumberControl
236
+ size={ '__unstable-large' }
237
+ onChange={ ( value ) => {
238
+ /**
239
+ * If the input is cleared, avoid switching
240
+ * back to "Auto" by setting a value of "1".
241
+ */
242
+ const validValue = value !== '' ? value : '1';
243
+ onChange( {
244
+ ...layout,
245
+ columnCount: validValue,
246
+ } );
247
+ } }
248
+ value={ columnCount }
249
+ min={ 1 }
250
+ label={ __( 'Columns' ) }
251
+ hideLabelFromVision
252
+ />
253
+ </FlexItem>
254
+ <FlexItem isBlock>
255
+ <RangeControl
256
+ value={ parseInt( columnCount, 10 ) } // RangeControl can't deal with strings.
257
+ onChange={ ( value ) =>
258
+ onChange( {
259
+ ...layout,
260
+ columnCount: value,
261
+ } )
262
+ }
263
+ min={ 1 }
264
+ max={ 16 }
265
+ withInputField={ false }
266
+ label={ __( 'Columns' ) }
267
+ hideLabelFromVision
268
+ />
269
+ </FlexItem>
270
+ </Flex>
271
+ </fieldset>
272
+ );
273
+ }
274
+
275
+ // Enables switching between grid types
276
+ function GridLayoutTypeControl( { layout, onChange } ) {
277
+ const { columnCount, minimumColumnWidth } = layout;
278
+
279
+ /**
280
+ * When switching, temporarily save any custom values set on the
281
+ * previous type so we can switch back without loss.
282
+ */
283
+ const [ tempColumnCount, setTempColumnCount ] = useState(
284
+ columnCount || 3
285
+ );
286
+ const [ tempMinimumColumnWidth, setTempMinimumColumnWidth ] = useState(
287
+ minimumColumnWidth || '12rem'
288
+ );
289
+
290
+ const isManual = !! columnCount ? 'manual' : 'auto';
291
+
292
+ const onChangeType = ( value ) => {
293
+ if ( value === 'manual' ) {
294
+ setTempMinimumColumnWidth( minimumColumnWidth || '12rem' );
295
+ } else {
296
+ setTempColumnCount( columnCount || 3 );
297
+ }
298
+ onChange( {
299
+ ...layout,
300
+ columnCount: value === 'manual' ? tempColumnCount : null,
301
+ minimumColumnWidth:
302
+ value === 'auto' ? tempMinimumColumnWidth : null,
303
+ } );
304
+ };
305
+
306
+ return (
307
+ <ToggleGroupControl
308
+ __nextHasNoMarginBottom={ true }
309
+ label={ __( 'Type' ) }
310
+ value={ isManual }
311
+ onChange={ onChangeType }
312
+ isBlock={ true }
313
+ >
314
+ <ToggleGroupControlOption
315
+ key={ 'auto' }
316
+ value="auto"
317
+ label={ __( 'Auto' ) }
318
+ />
319
+ <ToggleGroupControlOption
320
+ key={ 'manual' }
321
+ value="manual"
322
+ label={ __( 'Manual' ) }
323
+ />
324
+ </ToggleGroupControl>
246
325
  );
247
326
  }
@@ -4,8 +4,8 @@
4
4
  import grid from '../grid';
5
5
 
6
6
  describe( 'getLayoutStyle', () => {
7
- it( 'should return a single `grid-template-columns` property if no non-default params are provided', () => {
8
- const expected = `.editor-styles-wrapper .my-container { grid-template-columns: repeat(auto-fill, minmax(min(12rem, 100%), 1fr)); }`;
7
+ it( 'should return only `grid-template-columns` and `container-type` properties if no non-default params are provided', () => {
8
+ const expected = `.editor-styles-wrapper .my-container { grid-template-columns: repeat(auto-fill, minmax(min(12rem, 100%), 1fr)); container-type: inline-size; }`;
9
9
 
10
10
  const result = grid.getLayoutStyle( {
11
11
  selector: '.my-container',
@@ -16,6 +16,20 @@ describe( 'getLayoutStyle', () => {
16
16
  layoutDefinitions: undefined,
17
17
  } );
18
18
 
19
+ expect( result ).toBe( expected );
20
+ } );
21
+ it( 'should return only `grid-template-columns` if columnCount property is provided', () => {
22
+ const expected = `.editor-styles-wrapper .my-container { grid-template-columns: repeat(3, minmax(0, 1fr)); }`;
23
+
24
+ const result = grid.getLayoutStyle( {
25
+ selector: '.my-container',
26
+ layout: { columnCount: 3 },
27
+ style: {},
28
+ blockName: 'test-block',
29
+ hasBlockGapSupport: false,
30
+ layoutDefinitions: undefined,
31
+ } );
32
+
19
33
  expect( result ).toBe( expected );
20
34
  } );
21
35
  } );
@@ -331,36 +331,6 @@ export function toggleSelection( isSelectionEnabled = true ) {
331
331
  };
332
332
  }
333
333
 
334
- function getBlocksWithDefaultStylesApplied( blocks, blockEditorSettings ) {
335
- const preferredStyleVariations =
336
- blockEditorSettings?.__experimentalPreferredStyleVariations?.value ??
337
- {};
338
- return blocks.map( ( block ) => {
339
- const blockName = block.name;
340
- if ( ! hasBlockSupport( blockName, 'defaultStylePicker', true ) ) {
341
- return block;
342
- }
343
- if ( ! preferredStyleVariations[ blockName ] ) {
344
- return block;
345
- }
346
- const className = block.attributes?.className;
347
- if ( className?.includes( 'is-style-' ) ) {
348
- return block;
349
- }
350
- const { attributes = {} } = block;
351
- const blockStyle = preferredStyleVariations[ blockName ];
352
- return {
353
- ...block,
354
- attributes: {
355
- ...attributes,
356
- className: `${
357
- className || ''
358
- } is-style-${ blockStyle }`.trim(),
359
- },
360
- };
361
- } );
362
- }
363
-
364
334
  /* eslint-disable jsdoc/valid-types */
365
335
  /**
366
336
  * Action that replaces given blocks with one or more replacement blocks.
@@ -378,10 +348,7 @@ export const replaceBlocks =
378
348
  ( { select, dispatch, registry } ) => {
379
349
  /* eslint-enable jsdoc/valid-types */
380
350
  clientIds = castArray( clientIds );
381
- blocks = getBlocksWithDefaultStylesApplied(
382
- castArray( blocks ),
383
- select.getSettings()
384
- );
351
+ blocks = castArray( blocks );
385
352
  const rootClientId = select.getBlockRootClientId( clientIds[ 0 ] );
386
353
  // Replace is valid if the new blocks can be inserted in the root block.
387
354
  for ( let index = 0; index < blocks.length; index++ ) {
@@ -594,10 +561,7 @@ export const insertBlocks =
594
561
  );
595
562
  }
596
563
 
597
- blocks = getBlocksWithDefaultStylesApplied(
598
- castArray( blocks ),
599
- select.getSettings()
600
- );
564
+ blocks = castArray( blocks );
601
565
  const allowedBlocks = [];
602
566
  for ( const block of blocks ) {
603
567
  const isValid = select.canInsertBlockType(
@@ -380,107 +380,6 @@ describe( 'actions', () => {
380
380
  } );
381
381
 
382
382
  describe( 'insertBlocks', () => {
383
- it( 'should apply default styles to blocks if blocks do not contain a style', () => {
384
- const ribsBlock = {
385
- clientId: 'ribs',
386
- name: 'core/test-ribs',
387
- };
388
- const chickenBlock = {
389
- clientId: 'chicken',
390
- name: 'core/test-chicken',
391
- };
392
- const chickenRibsBlock = {
393
- clientId: 'chicken-ribs',
394
- name: 'core/test-chicken-ribs',
395
- };
396
- const blocks = [ ribsBlock, chickenBlock, chickenRibsBlock ];
397
-
398
- const select = {
399
- getSettings: () => ( {
400
- __experimentalPreferredStyleVariations: {
401
- value: {
402
- 'core/test-ribs': 'squared',
403
- 'core/test-chicken-ribs': 'colorful',
404
- },
405
- },
406
- } ),
407
- canInsertBlockType: () => true,
408
- };
409
- const dispatch = jest.fn();
410
-
411
- insertBlocks(
412
- blocks,
413
- 5,
414
- 'testrootid',
415
- false
416
- )( { select, dispatch } );
417
-
418
- expect( dispatch ).toHaveBeenCalledWith( {
419
- type: 'INSERT_BLOCKS',
420
- blocks: [
421
- {
422
- ...ribsBlock,
423
- attributes: { className: 'is-style-squared' },
424
- },
425
- chickenBlock,
426
- {
427
- ...chickenRibsBlock,
428
- attributes: { className: 'is-style-colorful' },
429
- },
430
- ],
431
- index: 5,
432
- rootClientId: 'testrootid',
433
- time: expect.any( Number ),
434
- updateSelection: false,
435
- initialPosition: null,
436
- } );
437
- } );
438
-
439
- it( 'should keep styles explicitly set even if different from the default', () => {
440
- const ribsWithStyleBlock = {
441
- clientId: 'ribs',
442
- name: 'core/test-ribs',
443
- attributes: {
444
- className: 'is-style-colorful',
445
- },
446
- };
447
- const blocks = [ ribsWithStyleBlock ];
448
-
449
- const select = {
450
- getSettings: () => ( {
451
- __experimentalPreferredStyleVariations: {
452
- value: {
453
- 'core/test-ribs': 'squared',
454
- },
455
- },
456
- } ),
457
- canInsertBlockType: () => true,
458
- };
459
- const dispatch = jest.fn();
460
-
461
- insertBlocks(
462
- blocks,
463
- 5,
464
- 'testrootid',
465
- false
466
- )( { select, dispatch } );
467
-
468
- expect( dispatch ).toHaveBeenCalledWith( {
469
- type: 'INSERT_BLOCKS',
470
- blocks: [
471
- {
472
- ...ribsWithStyleBlock,
473
- attributes: { className: 'is-style-colorful' },
474
- },
475
- ],
476
- index: 5,
477
- rootClientId: 'testrootid',
478
- time: expect.any( Number ),
479
- updateSelection: false,
480
- initialPosition: null,
481
- } );
482
- } );
483
-
484
383
  it( 'should filter the allowed blocks in INSERT_BLOCKS action', () => {
485
384
  const ribsBlock = {
486
385
  clientId: 'ribs',
package/src/style.scss CHANGED
@@ -16,7 +16,6 @@
16
16
  @import "./components/block-popover/style.scss";
17
17
  @import "./components/block-preview/style.scss";
18
18
  @import "./components/block-rename/style.scss";
19
- @import "./components/block-settings-menu/style.scss";
20
19
  @import "./components/block-styles/style.scss";
21
20
  @import "./components/block-switcher/style.scss";
22
21
  @import "./components/block-types-list/style.scss";
@@ -1,70 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = DefaultStylePicker;
7
- var _react = require("react");
8
- var _blocks = require("@wordpress/blocks");
9
- var _element = require("@wordpress/element");
10
- var _i18n = require("@wordpress/i18n");
11
- var _components = require("@wordpress/components");
12
- var _data = require("@wordpress/data");
13
- var _store = require("../../store");
14
- var _utils = require("../block-styles/utils");
15
- /**
16
- * WordPress dependencies
17
- */
18
-
19
- /**
20
- * Internal dependencies
21
- */
22
-
23
- function DefaultStylePicker({
24
- blockName
25
- }) {
26
- const {
27
- preferredStyle,
28
- onUpdatePreferredStyleVariations,
29
- styles
30
- } = (0, _data.useSelect)(select => {
31
- var _preferredStyleVariat;
32
- const settings = select(_store.store).getSettings();
33
- const preferredStyleVariations = settings.__experimentalPreferredStyleVariations;
34
- return {
35
- preferredStyle: preferredStyleVariations?.value?.[blockName],
36
- onUpdatePreferredStyleVariations: (_preferredStyleVariat = preferredStyleVariations?.onChange) !== null && _preferredStyleVariat !== void 0 ? _preferredStyleVariat : null,
37
- styles: select(_blocks.store).getBlockStyles(blockName)
38
- };
39
- }, [blockName]);
40
- const selectOptions = (0, _element.useMemo)(() => [{
41
- label: (0, _i18n.__)('Not set'),
42
- value: ''
43
- }, ...styles.map(({
44
- label,
45
- name
46
- }) => ({
47
- label,
48
- value: name
49
- }))], [styles]);
50
- const defaultStyleName = (0, _element.useMemo)(() => (0, _utils.getDefaultStyle)(styles)?.name, [styles]);
51
- const selectOnChange = (0, _element.useCallback)(blockStyle => {
52
- onUpdatePreferredStyleVariations(blockName, blockStyle);
53
- }, [blockName, onUpdatePreferredStyleVariations]);
54
-
55
- // Until the functionality is migrated to global styles,
56
- // only show the default style picker if a non-default style has already been selected.
57
- if (!preferredStyle || preferredStyle === defaultStyleName) {
58
- return null;
59
- }
60
- return onUpdatePreferredStyleVariations && (0, _react.createElement)("div", {
61
- className: "default-style-picker__default-switcher"
62
- }, (0, _react.createElement)(_components.SelectControl, {
63
- __nextHasNoMarginBottom: true,
64
- options: selectOptions,
65
- value: preferredStyle || '',
66
- label: (0, _i18n.__)('Default Style'),
67
- onChange: selectOnChange
68
- }));
69
- }
70
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_blocks","require","_element","_i18n","_components","_data","_store","_utils","DefaultStylePicker","blockName","preferredStyle","onUpdatePreferredStyleVariations","styles","useSelect","select","_preferredStyleVariat","settings","blockEditorStore","getSettings","preferredStyleVariations","__experimentalPreferredStyleVariations","value","onChange","blocksStore","getBlockStyles","selectOptions","useMemo","label","__","map","name","defaultStyleName","getDefaultStyle","selectOnChange","useCallback","blockStyle","_react","createElement","className","SelectControl","__nextHasNoMarginBottom","options"],"sources":["@wordpress/block-editor/src/components/default-style-picker/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as blocksStore } from '@wordpress/blocks';\nimport { useMemo, useCallback } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { SelectControl } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { getDefaultStyle } from '../block-styles/utils';\n\nexport default function DefaultStylePicker( { blockName } ) {\n\tconst { preferredStyle, onUpdatePreferredStyleVariations, styles } =\n\t\tuseSelect(\n\t\t\t( select ) => {\n\t\t\t\tconst settings = select( blockEditorStore ).getSettings();\n\t\t\t\tconst preferredStyleVariations =\n\t\t\t\t\tsettings.__experimentalPreferredStyleVariations;\n\t\t\t\treturn {\n\t\t\t\t\tpreferredStyle:\n\t\t\t\t\t\tpreferredStyleVariations?.value?.[ blockName ],\n\t\t\t\t\tonUpdatePreferredStyleVariations:\n\t\t\t\t\t\tpreferredStyleVariations?.onChange ?? null,\n\t\t\t\t\tstyles: select( blocksStore ).getBlockStyles( blockName ),\n\t\t\t\t};\n\t\t\t},\n\t\t\t[ blockName ]\n\t\t);\n\tconst selectOptions = useMemo(\n\t\t() => [\n\t\t\t{ label: __( 'Not set' ), value: '' },\n\t\t\t...styles.map( ( { label, name } ) => ( { label, value: name } ) ),\n\t\t],\n\t\t[ styles ]\n\t);\n\tconst defaultStyleName = useMemo(\n\t\t() => getDefaultStyle( styles )?.name,\n\t\t[ styles ]\n\t);\n\tconst selectOnChange = useCallback(\n\t\t( blockStyle ) => {\n\t\t\tonUpdatePreferredStyleVariations( blockName, blockStyle );\n\t\t},\n\t\t[ blockName, onUpdatePreferredStyleVariations ]\n\t);\n\n\t// Until the functionality is migrated to global styles,\n\t// only show the default style picker if a non-default style has already been selected.\n\tif ( ! preferredStyle || preferredStyle === defaultStyleName ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\tonUpdatePreferredStyleVariations && (\n\t\t\t<div className=\"default-style-picker__default-switcher\">\n\t\t\t\t<SelectControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\toptions={ selectOptions }\n\t\t\t\t\tvalue={ preferredStyle || '' }\n\t\t\t\t\tlabel={ __( 'Default Style' ) }\n\t\t\t\t\tonChange={ selectOnChange }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t)\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AAKA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AAbA;AACA;AACA;;AAOA;AACA;AACA;;AAIe,SAASO,kBAAkBA,CAAE;EAAEC;AAAU,CAAC,EAAG;EAC3D,MAAM;IAAEC,cAAc;IAAEC,gCAAgC;IAAEC;EAAO,CAAC,GACjE,IAAAC,eAAS,EACNC,MAAM,IAAM;IAAA,IAAAC,qBAAA;IACb,MAAMC,QAAQ,GAAGF,MAAM,CAAEG,YAAiB,CAAC,CAACC,WAAW,CAAC,CAAC;IACzD,MAAMC,wBAAwB,GAC7BH,QAAQ,CAACI,sCAAsC;IAChD,OAAO;MACNV,cAAc,EACbS,wBAAwB,EAAEE,KAAK,GAAIZ,SAAS,CAAE;MAC/CE,gCAAgC,GAAAI,qBAAA,GAC/BI,wBAAwB,EAAEG,QAAQ,cAAAP,qBAAA,cAAAA,qBAAA,GAAI,IAAI;MAC3CH,MAAM,EAAEE,MAAM,CAAES,aAAY,CAAC,CAACC,cAAc,CAAEf,SAAU;IACzD,CAAC;EACF,CAAC,EACD,CAAEA,SAAS,CACZ,CAAC;EACF,MAAMgB,aAAa,GAAG,IAAAC,gBAAO,EAC5B,MAAM,CACL;IAAEC,KAAK,EAAE,IAAAC,QAAE,EAAE,SAAU,CAAC;IAAEP,KAAK,EAAE;EAAG,CAAC,EACrC,GAAGT,MAAM,CAACiB,GAAG,CAAE,CAAE;IAAEF,KAAK;IAAEG;EAAK,CAAC,MAAQ;IAAEH,KAAK;IAAEN,KAAK,EAAES;EAAK,CAAC,CAAG,CAAC,CAClE,EACD,CAAElB,MAAM,CACT,CAAC;EACD,MAAMmB,gBAAgB,GAAG,IAAAL,gBAAO,EAC/B,MAAM,IAAAM,sBAAe,EAAEpB,MAAO,CAAC,EAAEkB,IAAI,EACrC,CAAElB,MAAM,CACT,CAAC;EACD,MAAMqB,cAAc,GAAG,IAAAC,oBAAW,EAC/BC,UAAU,IAAM;IACjBxB,gCAAgC,CAAEF,SAAS,EAAE0B,UAAW,CAAC;EAC1D,CAAC,EACD,CAAE1B,SAAS,EAAEE,gCAAgC,CAC9C,CAAC;;EAED;EACA;EACA,IAAK,CAAED,cAAc,IAAIA,cAAc,KAAKqB,gBAAgB,EAAG;IAC9D,OAAO,IAAI;EACZ;EAEA,OACCpB,gCAAgC,IAC/B,IAAAyB,MAAA,CAAAC,aAAA;IAAKC,SAAS,EAAC;EAAwC,GACtD,IAAAF,MAAA,CAAAC,aAAA,EAACjC,WAAA,CAAAmC,aAAa;IACbC,uBAAuB;IACvBC,OAAO,EAAGhB,aAAe;IACzBJ,KAAK,EAAGX,cAAc,IAAI,EAAI;IAC9BiB,KAAK,EAAG,IAAAC,QAAE,EAAE,eAAgB,CAAG;IAC/BN,QAAQ,EAAGW;EAAgB,CAC3B,CACG,CACL;AAEH"}