@wordpress/block-library 8.28.3 → 8.28.5

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 (110) hide show
  1. package/build/block/deprecated.js +71 -11
  2. package/build/block/deprecated.js.map +1 -1
  3. package/build/block/edit.js +49 -24
  4. package/build/block/edit.js.map +1 -1
  5. package/build/button/edit.js +1 -1
  6. package/build/button/edit.js.map +1 -1
  7. package/build/buttons/transforms.js +16 -2
  8. package/build/buttons/transforms.js.map +1 -1
  9. package/build/code/transforms.js +17 -6
  10. package/build/code/transforms.js.map +1 -1
  11. package/build/cover/edit/block-controls.js +14 -3
  12. package/build/cover/edit/block-controls.js.map +1 -1
  13. package/build/cover/edit/inspector-controls.js +1 -1
  14. package/build/cover/edit/inspector-controls.js.map +1 -1
  15. package/build/heading/transforms.js +17 -4
  16. package/build/heading/transforms.js.map +1 -1
  17. package/build/image/edit.js +8 -4
  18. package/build/image/edit.js.map +1 -1
  19. package/build/image/image.js +22 -8
  20. package/build/image/image.js.map +1 -1
  21. package/build/list-item/edit.js +1 -3
  22. package/build/list-item/edit.js.map +1 -1
  23. package/build/list-item/hooks/index.js +0 -7
  24. package/build/list-item/hooks/index.js.map +1 -1
  25. package/build/list-item/index.js +4 -1
  26. package/build/list-item/index.js.map +1 -1
  27. package/build/post-featured-image/edit.js +8 -11
  28. package/build/post-featured-image/edit.js.map +1 -1
  29. package/build/post-title/edit.js +2 -2
  30. package/build/post-title/edit.js.map +1 -1
  31. package/build/site-logo/edit.js +7 -2
  32. package/build/site-logo/edit.js.map +1 -1
  33. package/build/utils/caption.js +15 -5
  34. package/build/utils/caption.js.map +1 -1
  35. package/build/utils/get-transformed-metadata.js +57 -0
  36. package/build/utils/get-transformed-metadata.js.map +1 -0
  37. package/build-module/block/deprecated.js +71 -11
  38. package/build-module/block/deprecated.js.map +1 -1
  39. package/build-module/block/edit.js +49 -24
  40. package/build-module/block/edit.js.map +1 -1
  41. package/build-module/button/edit.js +2 -2
  42. package/build-module/button/edit.js.map +1 -1
  43. package/build-module/buttons/transforms.js +16 -2
  44. package/build-module/buttons/transforms.js.map +1 -1
  45. package/build-module/code/transforms.js +17 -6
  46. package/build-module/code/transforms.js.map +1 -1
  47. package/build-module/cover/edit/block-controls.js +15 -4
  48. package/build-module/cover/edit/block-controls.js.map +1 -1
  49. package/build-module/cover/edit/inspector-controls.js +1 -1
  50. package/build-module/cover/edit/inspector-controls.js.map +1 -1
  51. package/build-module/heading/transforms.js +17 -4
  52. package/build-module/heading/transforms.js.map +1 -1
  53. package/build-module/image/edit.js +9 -5
  54. package/build-module/image/edit.js.map +1 -1
  55. package/build-module/image/image.js +23 -9
  56. package/build-module/image/image.js.map +1 -1
  57. package/build-module/list-item/edit.js +2 -4
  58. package/build-module/list-item/edit.js.map +1 -1
  59. package/build-module/list-item/hooks/index.js +0 -1
  60. package/build-module/list-item/hooks/index.js.map +1 -1
  61. package/build-module/list-item/index.js +4 -1
  62. package/build-module/list-item/index.js.map +1 -1
  63. package/build-module/post-featured-image/edit.js +9 -12
  64. package/build-module/post-featured-image/edit.js.map +1 -1
  65. package/build-module/post-title/edit.js +2 -2
  66. package/build-module/post-title/edit.js.map +1 -1
  67. package/build-module/site-logo/edit.js +7 -2
  68. package/build-module/site-logo/edit.js.map +1 -1
  69. package/build-module/utils/caption.js +13 -3
  70. package/build-module/utils/caption.js.map +1 -1
  71. package/build-module/utils/get-transformed-metadata.js +51 -0
  72. package/build-module/utils/get-transformed-metadata.js.map +1 -0
  73. package/build-style/common-rtl.css +1 -0
  74. package/build-style/common.css +1 -0
  75. package/build-style/cover/style-rtl.css +2 -1
  76. package/build-style/cover/style.css +2 -1
  77. package/build-style/search/style-rtl.css +2 -0
  78. package/build-style/search/style.css +2 -0
  79. package/build-style/style-rtl.css +4 -1
  80. package/build-style/style.css +4 -1
  81. package/package.json +13 -13
  82. package/src/block/deprecated.js +76 -11
  83. package/src/block/edit.js +64 -19
  84. package/src/block/index.php +21 -12
  85. package/src/button/edit.js +2 -1
  86. package/src/buttons/transforms.js +14 -4
  87. package/src/code/transforms.js +20 -5
  88. package/src/cover/edit/block-controls.js +16 -2
  89. package/src/cover/edit/inspector-controls.js +5 -1
  90. package/src/cover/style.scss +3 -2
  91. package/src/footnotes/index.php +1 -1
  92. package/src/heading/transforms.js +27 -8
  93. package/src/image/edit.js +12 -4
  94. package/src/image/image.js +32 -20
  95. package/src/list-item/edit.js +1 -2
  96. package/src/list-item/hooks/index.js +0 -1
  97. package/src/list-item/index.js +3 -0
  98. package/src/navigation/index.php +8 -4
  99. package/src/post-featured-image/edit.js +9 -11
  100. package/src/post-title/edit.js +49 -43
  101. package/src/search/index.php +1 -1
  102. package/src/search/style.scss +2 -0
  103. package/src/site-logo/edit.js +10 -5
  104. package/src/utils/caption.js +10 -1
  105. package/src/utils/get-transformed-metadata.js +65 -0
  106. package/build/list-item/hooks/use-copy.js +0 -39
  107. package/build/list-item/hooks/use-copy.js.map +0 -1
  108. package/build-module/list-item/hooks/use-copy.js +0 -32
  109. package/build-module/list-item/hooks/use-copy.js.map +0 -1
  110. package/src/list-item/hooks/use-copy.js +0 -38
@@ -613,7 +613,8 @@
613
613
  justify-content: center;
614
614
  align-items: center;
615
615
  padding: 1em;
616
- overflow-x: clip;
616
+ overflow: hidden;
617
+ overflow: clip;
617
618
  box-sizing: border-box; direction: ltr;
618
619
  /**
619
620
  * Set a default background color for has-background-dim _unless_ it includes another
@@ -3252,6 +3253,8 @@ ul.wp-block-rss.is-grid li {
3252
3253
  .wp-block-search__button svg {
3253
3254
  min-width: 24px;
3254
3255
  min-height: 24px;
3256
+ width: 1.25em;
3257
+ height: 1.25em;
3255
3258
  fill: currentColor;
3256
3259
  vertical-align: text-bottom;
3257
3260
  }
@@ -618,7 +618,8 @@
618
618
  justify-content: center;
619
619
  align-items: center;
620
620
  padding: 1em;
621
- overflow-x: clip;
621
+ overflow: hidden;
622
+ overflow: clip;
622
623
  box-sizing: border-box;
623
624
  /*rtl:raw: direction: ltr; */
624
625
  /**
@@ -3286,6 +3287,8 @@ ul.wp-block-rss.is-grid li {
3286
3287
  .wp-block-search__button svg {
3287
3288
  min-width: 24px;
3288
3289
  min-height: 24px;
3290
+ width: 1.25em;
3291
+ height: 1.25em;
3289
3292
  fill: currentColor;
3290
3293
  vertical-align: text-bottom;
3291
3294
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/block-library",
3
- "version": "8.28.3",
3
+ "version": "8.28.5",
4
4
  "description": "Block library for the WordPress editor.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -35,11 +35,11 @@
35
35
  "@wordpress/api-fetch": "^6.48.1",
36
36
  "@wordpress/autop": "^3.51.1",
37
37
  "@wordpress/blob": "^3.51.1",
38
- "@wordpress/block-editor": "^12.19.3",
39
- "@wordpress/blocks": "^12.28.3",
40
- "@wordpress/components": "^26.0.2",
38
+ "@wordpress/block-editor": "^12.19.5",
39
+ "@wordpress/blocks": "^12.28.5",
40
+ "@wordpress/components": "^26.0.4",
41
41
  "@wordpress/compose": "^6.28.1",
42
- "@wordpress/core-data": "^6.28.3",
42
+ "@wordpress/core-data": "^6.28.5",
43
43
  "@wordpress/data": "^9.21.1",
44
44
  "@wordpress/date": "^4.51.1",
45
45
  "@wordpress/deprecated": "^3.51.1",
@@ -49,17 +49,17 @@
49
49
  "@wordpress/hooks": "^3.51.1",
50
50
  "@wordpress/html-entities": "^3.51.1",
51
51
  "@wordpress/i18n": "^4.51.1",
52
- "@wordpress/icons": "^9.42.1",
53
- "@wordpress/interactivity": "^5.0.1",
54
- "@wordpress/interactivity-router": "^1.1.1",
52
+ "@wordpress/icons": "^9.42.3",
53
+ "@wordpress/interactivity": "^5.0.3",
54
+ "@wordpress/interactivity-router": "^1.1.3",
55
55
  "@wordpress/keycodes": "^3.51.1",
56
56
  "@wordpress/notices": "^4.19.1",
57
- "@wordpress/patterns": "^1.12.3",
57
+ "@wordpress/patterns": "^1.12.5",
58
58
  "@wordpress/primitives": "^3.49.1",
59
59
  "@wordpress/private-apis": "^0.33.1",
60
- "@wordpress/reusable-blocks": "^4.28.3",
61
- "@wordpress/rich-text": "^6.28.2",
62
- "@wordpress/server-side-render": "^4.28.3",
60
+ "@wordpress/reusable-blocks": "^4.28.5",
61
+ "@wordpress/rich-text": "^6.28.3",
62
+ "@wordpress/server-side-render": "^4.28.5",
63
63
  "@wordpress/url": "^3.52.1",
64
64
  "@wordpress/viewport": "^5.28.1",
65
65
  "@wordpress/wordcount": "^3.51.1",
@@ -80,5 +80,5 @@
80
80
  "publishConfig": {
81
81
  "access": "public"
82
82
  },
83
- "gitHead": "b12d75c5c5256fda2a0509bb432e20ddd3354d5e"
83
+ "gitHead": "4927ea437069f9aed12f696df294a79bd8e12fd5"
84
84
  }
@@ -1,4 +1,75 @@
1
- // v1: Migrate and rename the `overrides` attribute to the `content` attribute.
1
+ const isObject = ( obj ) =>
2
+ typeof obj === 'object' && ! Array.isArray( obj ) && obj !== null;
3
+
4
+ // v2: Migrate to a more condensed version of the 'content' attribute attribute.
5
+ const v2 = {
6
+ attributes: {
7
+ ref: {
8
+ type: 'number',
9
+ },
10
+ content: {
11
+ type: 'object',
12
+ },
13
+ },
14
+ supports: {
15
+ customClassName: false,
16
+ html: false,
17
+ inserter: false,
18
+ renaming: false,
19
+ },
20
+ // Force this deprecation to run whenever there's a values sub-property that's an object.
21
+ //
22
+ // This could fail in the future if a block ever has binding to a `values` attribute.
23
+ // Some extra protection is added to ensure `values` is an object, but this only reduces
24
+ // the likelihood, it doesn't solve it completely.
25
+ isEligible( { content } ) {
26
+ return (
27
+ !! content &&
28
+ Object.keys( content ).every(
29
+ ( contentKey ) =>
30
+ content[ contentKey ].values &&
31
+ isObject( content[ contentKey ].values )
32
+ )
33
+ );
34
+ },
35
+ /*
36
+ * Old attribute format:
37
+ * content: {
38
+ * "V98q_x": {
39
+ * // The attribute values are now stored as a 'values' sub-property.
40
+ * values: { content: 'My content value' },
41
+ * // ... additional metadata, like the block name can be stored here.
42
+ * }
43
+ * }
44
+ *
45
+ * New attribute format:
46
+ * content: {
47
+ * "V98q_x": {
48
+ * content: 'My content value',
49
+ * }
50
+ * }
51
+ */
52
+ migrate( attributes ) {
53
+ const { content, ...retainedAttributes } = attributes;
54
+
55
+ if ( content && Object.keys( content ).length ) {
56
+ const updatedContent = { ...content };
57
+
58
+ for ( const contentKey in content ) {
59
+ updatedContent[ contentKey ] = content[ contentKey ].values;
60
+ }
61
+
62
+ return {
63
+ ...retainedAttributes,
64
+ content: updatedContent,
65
+ };
66
+ }
67
+
68
+ return attributes;
69
+ },
70
+ };
71
+
72
+ // v1: Rename the `overrides` attribute to the `content` attribute.
2
73
  const v1 = {
3
74
  attributes: {
4
75
  ref: {
@@ -23,16 +94,12 @@ const v1 = {
23
94
  * overrides: {
24
95
  * // An key is an id that represents a block.
25
96
  * // The values are the attribute values of the block.
26
- * "V98q_x": { content: 'dwefwefwefwe' }
97
+ * "V98q_x": { content: 'My content value' }
27
98
  * }
28
99
  *
29
100
  * New attribute format:
30
101
  * content: {
31
- * "V98q_x": {
32
- * // The attribute values are now stored as a 'values' sub-property.
33
- * values: { content: 'dwefwefwefwe' },
34
- * // ... additional metadata, like the block name can be stored here.
35
- * }
102
+ * "V98q_x": { content: 'My content value' }
36
103
  * }
37
104
  *
38
105
  */
@@ -42,9 +109,7 @@ const v1 = {
42
109
  const content = {};
43
110
 
44
111
  Object.keys( overrides ).forEach( ( id ) => {
45
- content[ id ] = {
46
- values: overrides[ id ],
47
- };
112
+ content[ id ] = overrides[ id ];
48
113
  } );
49
114
 
50
115
  return {
@@ -54,4 +119,4 @@ const v1 = {
54
119
  },
55
120
  };
56
121
 
57
- export default [ v1 ];
122
+ export default [ v2, v1 ];
package/src/block/edit.js CHANGED
@@ -42,6 +42,25 @@ const { PARTIAL_SYNCING_SUPPORTED_BLOCKS } = unlock( patternsPrivateApis );
42
42
 
43
43
  const fullAlignments = [ 'full', 'wide', 'left', 'right' ];
44
44
 
45
+ function getLegacyIdMap( blocks, content, nameCount = {} ) {
46
+ let idToClientIdMap = {};
47
+ for ( const block of blocks ) {
48
+ if ( block?.innerBlocks?.length ) {
49
+ idToClientIdMap = {
50
+ ...idToClientIdMap,
51
+ ...getLegacyIdMap( block.innerBlocks, content, nameCount ),
52
+ };
53
+ }
54
+
55
+ const id = block.attributes.metadata?.id;
56
+ const clientId = block.clientId;
57
+ if ( id && content?.[ id ] ) {
58
+ idToClientIdMap[ clientId ] = id;
59
+ }
60
+ }
61
+ return idToClientIdMap;
62
+ }
63
+
45
64
  const useInferredLayout = ( blocks, parentLayout ) => {
46
65
  const initialInferredAlignmentRef = useRef();
47
66
 
@@ -101,25 +120,31 @@ function getOverridableAttributes( block ) {
101
120
  function applyInitialContentValuesToInnerBlocks(
102
121
  blocks,
103
122
  content = {},
104
- defaultValues
123
+ defaultValues,
124
+ legacyIdMap
105
125
  ) {
106
126
  return blocks.map( ( block ) => {
107
127
  const innerBlocks = applyInitialContentValuesToInnerBlocks(
108
128
  block.innerBlocks,
109
129
  content,
110
- defaultValues
130
+ defaultValues,
131
+ legacyIdMap
111
132
  );
112
- const blockId = block.attributes.metadata?.id;
113
- if ( ! hasOverridableAttributes( block ) || ! blockId )
133
+ const metadataName =
134
+ legacyIdMap?.[ block.clientId ] ?? block.attributes.metadata?.name;
135
+
136
+ if ( ! metadataName || ! hasOverridableAttributes( block ) ) {
114
137
  return { ...block, innerBlocks };
138
+ }
139
+
115
140
  const attributes = getOverridableAttributes( block );
116
141
  const newAttributes = { ...block.attributes };
117
142
  for ( const attributeKey of attributes ) {
118
- defaultValues[ blockId ] ??= {};
119
- defaultValues[ blockId ][ attributeKey ] =
143
+ defaultValues[ metadataName ] ??= {};
144
+ defaultValues[ metadataName ][ attributeKey ] =
120
145
  block.attributes[ attributeKey ];
121
146
 
122
- const contentValues = content[ blockId ]?.values;
147
+ const contentValues = content[ metadataName ];
123
148
  if ( contentValues?.[ attributeKey ] !== undefined ) {
124
149
  newAttributes[ attributeKey ] = contentValues[ attributeKey ];
125
150
  }
@@ -142,29 +167,40 @@ function isAttributeEqual( attribute1, attribute2 ) {
142
167
  return attribute1 === attribute2;
143
168
  }
144
169
 
145
- function getContentValuesFromInnerBlocks( blocks, defaultValues ) {
170
+ function getContentValuesFromInnerBlocks( blocks, defaultValues, legacyIdMap ) {
146
171
  /** @type {Record<string, { values: Record<string, unknown>}>} */
147
172
  const content = {};
148
173
  for ( const block of blocks ) {
149
174
  if ( block.name === patternBlockName ) continue;
150
- Object.assign(
151
- content,
152
- getContentValuesFromInnerBlocks( block.innerBlocks, defaultValues )
153
- );
154
- const blockId = block.attributes.metadata?.id;
155
- if ( ! hasOverridableAttributes( block ) || ! blockId ) continue;
175
+ if ( block.innerBlocks.length ) {
176
+ Object.assign(
177
+ content,
178
+ getContentValuesFromInnerBlocks(
179
+ block.innerBlocks,
180
+ defaultValues,
181
+ legacyIdMap
182
+ )
183
+ );
184
+ }
185
+ const metadataName =
186
+ legacyIdMap?.[ block.clientId ] ?? block.attributes.metadata?.name;
187
+ if ( ! metadataName || ! hasOverridableAttributes( block ) ) {
188
+ continue;
189
+ }
190
+
156
191
  const attributes = getOverridableAttributes( block );
192
+
157
193
  for ( const attributeKey of attributes ) {
158
194
  if (
159
195
  ! isAttributeEqual(
160
196
  block.attributes[ attributeKey ],
161
- defaultValues[ blockId ][ attributeKey ]
197
+ defaultValues?.[ metadataName ]?.[ attributeKey ]
162
198
  )
163
199
  ) {
164
- content[ blockId ] ??= { values: {}, blockName: block.name };
200
+ content[ metadataName ] ??= {};
165
201
  // TODO: We need a way to represent `undefined` in the serialized overrides.
166
202
  // Also see: https://github.com/WordPress/gutenberg/pull/57249#discussion_r1452987871
167
- content[ blockId ].values[ attributeKey ] =
203
+ content[ metadataName ][ attributeKey ] =
168
204
  block.attributes[ attributeKey ] === undefined
169
205
  ? // TODO: We use an empty string to represent undefined for now until
170
206
  // we support a richer format for overrides and the block binding API.
@@ -278,8 +314,15 @@ export default function ReusableBlockEdit( {
278
314
  [ editedRecord.blocks, editedRecord.content ]
279
315
  );
280
316
 
317
+ const legacyIdMap = useRef( {} );
318
+
281
319
  // Apply the initial overrides from the pattern block to the inner blocks.
282
320
  useEffect( () => {
321
+ // Build a map of clientIds to the old nano id system to provide back compat.
322
+ legacyIdMap.current = getLegacyIdMap(
323
+ initialBlocks,
324
+ initialContent.current
325
+ );
283
326
  defaultContent.current = {};
284
327
  const originalEditingMode = getBlockEditingMode( patternClientId );
285
328
  // Replace the contents of the blocks with the overrides.
@@ -291,7 +334,8 @@ export default function ReusableBlockEdit( {
291
334
  applyInitialContentValuesToInnerBlocks(
292
335
  initialBlocks,
293
336
  initialContent.current,
294
- defaultContent.current
337
+ defaultContent.current,
338
+ legacyIdMap.current
295
339
  )
296
340
  );
297
341
  } );
@@ -343,7 +387,8 @@ export default function ReusableBlockEdit( {
343
387
  setAttributes( {
344
388
  content: getContentValuesFromInnerBlocks(
345
389
  blocks,
346
- defaultContent.current
390
+ defaultContent.current,
391
+ legacyIdMap.current
347
392
  ),
348
393
  } );
349
394
  } );
@@ -46,26 +46,35 @@ function render_block_core_block( $attributes ) {
46
46
  $content = $wp_embed->run_shortcode( $reusable_block->post_content );
47
47
  $content = $wp_embed->autoembed( $content );
48
48
 
49
- // Back compat, the content attribute was previously named overrides and
50
- // had a slightly different format. For blocks that have not been migrated,
51
- // also convert the format here so that the provided `pattern/overrides`
52
- // context is correct.
53
- if ( isset( $attributes['overrides'] ) && ! isset( $attributes['content'] ) ) {
54
- $migrated_content = array();
55
- foreach ( $attributes['overrides'] as $id => $values ) {
56
- $migrated_content[ $id ] = array(
57
- 'values' => $values,
58
- );
49
+ // Back compat.
50
+ // For blocks that have not been migrated in the editor, add some back compat
51
+ // so that front-end rendering continues to work.
52
+
53
+ // This matches the `v2` deprecation. Removes the inner `values` property
54
+ // from every item.
55
+ if ( isset( $attributes['content'] ) ) {
56
+ foreach ( $attributes['content'] as &$content_data ) {
57
+ if ( isset( $content_data['values'] ) ) {
58
+ $is_assoc_array = is_array( $content_data['values'] ) && ! wp_is_numeric_array( $content_data['values'] );
59
+
60
+ if ( $is_assoc_array ) {
61
+ $content_data = $content_data['values'];
62
+ }
63
+ }
59
64
  }
60
- $attributes['content'] = $migrated_content;
61
65
  }
62
- $has_pattern_overrides = isset( $attributes['content'] );
66
+
67
+ // This matches the `v1` deprecation. Rename `overrides` to `content`.
68
+ if ( isset( $attributes['overrides'] ) && ! isset( $attributes['content'] ) ) {
69
+ $attributes['content'] = $attributes['overrides'];
70
+ }
63
71
 
64
72
  /**
65
73
  * We set the `pattern/overrides` context through the `render_block_context`
66
74
  * filter so that it is available when a pattern's inner blocks are
67
75
  * rendering via do_blocks given it only receives the inner content.
68
76
  */
77
+ $has_pattern_overrides = isset( $attributes['content'] );
69
78
  if ( $has_pattern_overrides ) {
70
79
  $filter_block_context = static function ( $context ) use ( $attributes ) {
71
80
  $context['pattern/overrides'] = $attributes['content'];
@@ -45,6 +45,7 @@ import {
45
45
  createBlock,
46
46
  cloneBlock,
47
47
  getDefaultBlockName,
48
+ store as blocksStore,
48
49
  } from '@wordpress/blocks';
49
50
  import { useMergeRefs, useRefEffect } from '@wordpress/compose';
50
51
  import { useSelect, useDispatch } from '@wordpress/data';
@@ -239,7 +240,7 @@ function ButtonEdit( props ) {
239
240
  }
240
241
 
241
242
  const blockBindingsSource = unlock(
242
- select( blockEditorStore )
243
+ select( blocksStore )
243
244
  ).getBlockBindingsSource( metadata?.bindings?.url?.source );
244
245
 
245
246
  return {
@@ -4,6 +4,11 @@
4
4
  import { createBlock } from '@wordpress/blocks';
5
5
  import { __unstableCreateElement as createElement } from '@wordpress/rich-text';
6
6
 
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ import { getTransformedMetadata } from '../utils/get-transformed-metadata';
11
+
7
12
  const transforms = {
8
13
  from: [
9
14
  {
@@ -33,10 +38,8 @@ const transforms = {
33
38
  {},
34
39
  // Loop the selected buttons.
35
40
  buttons.map( ( attributes ) => {
36
- const element = createElement(
37
- document,
38
- attributes.content
39
- );
41
+ const { content, metadata } = attributes;
42
+ const element = createElement( document, content );
40
43
  // Remove any HTML tags.
41
44
  const text = element.innerText || '';
42
45
  // Get first url.
@@ -46,6 +49,13 @@ const transforms = {
46
49
  return createBlock( 'core/button', {
47
50
  text,
48
51
  url,
52
+ metadata: getTransformedMetadata(
53
+ metadata,
54
+ 'core/button',
55
+ ( { content: contentBinding } ) => ( {
56
+ text: contentBinding,
57
+ } )
58
+ ),
49
59
  } );
50
60
  } )
51
61
  ),
@@ -4,6 +4,11 @@
4
4
  import { createBlock } from '@wordpress/blocks';
5
5
  import { create, toHTMLString } from '@wordpress/rich-text';
6
6
 
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ import { getTransformedMetadata } from '../utils/get-transformed-metadata';
11
+
7
12
  const transforms = {
8
13
  from: [
9
14
  {
@@ -14,17 +19,21 @@ const transforms = {
14
19
  {
15
20
  type: 'block',
16
21
  blocks: [ 'core/paragraph' ],
17
- transform: ( { content } ) =>
18
- createBlock( 'core/code', { content } ),
22
+ transform: ( { content, metadata } ) =>
23
+ createBlock( 'core/code', {
24
+ content,
25
+ metadata: getTransformedMetadata( metadata, 'core/code' ),
26
+ } ),
19
27
  },
20
28
  {
21
29
  type: 'block',
22
30
  blocks: [ 'core/html' ],
23
- transform: ( { content: text } ) => {
31
+ transform: ( { content: text, metadata } ) => {
24
32
  return createBlock( 'core/code', {
25
33
  // The HTML is plain text (with plain line breaks), so
26
34
  // convert it to rich text.
27
35
  content: toHTMLString( { value: create( { text } ) } ),
36
+ metadata: getTransformedMetadata( metadata, 'core/code' ),
28
37
  } );
29
38
  },
30
39
  },
@@ -51,8 +60,14 @@ const transforms = {
51
60
  {
52
61
  type: 'block',
53
62
  blocks: [ 'core/paragraph' ],
54
- transform: ( { content } ) =>
55
- createBlock( 'core/paragraph', { content } ),
63
+ transform: ( { content, metadata } ) =>
64
+ createBlock( 'core/paragraph', {
65
+ content,
66
+ metadata: getTransformedMetadata(
67
+ metadata,
68
+ 'core/paragraph'
69
+ ),
70
+ } ),
56
71
  },
57
72
  ],
58
73
  };
@@ -8,6 +8,7 @@ import {
8
8
  MediaReplaceFlow,
9
9
  __experimentalBlockAlignmentMatrixControl as BlockAlignmentMatrixControl,
10
10
  __experimentalBlockFullHeightAligmentControl as FullHeightAlignmentControl,
11
+ privateApis as blockEditorPrivateApis,
11
12
  } from '@wordpress/block-editor';
12
13
  import { __ } from '@wordpress/i18n';
13
14
 
@@ -15,6 +16,9 @@ import { __ } from '@wordpress/i18n';
15
16
  * Internal dependencies
16
17
  */
17
18
  import { ALLOWED_MEDIA_TYPES } from '../shared';
19
+ import { unlock } from '../../lock-unlock';
20
+
21
+ const { cleanEmptyObject } = unlock( blockEditorPrivateApis );
18
22
 
19
23
  export default function CoverBlockControls( {
20
24
  attributes,
@@ -30,7 +34,10 @@ export default function CoverBlockControls( {
30
34
  const [ prevMinHeightValue, setPrevMinHeightValue ] = useState( minHeight );
31
35
  const [ prevMinHeightUnit, setPrevMinHeightUnit ] =
32
36
  useState( minHeightUnit );
33
- const isMinFullHeight = minHeightUnit === 'vh' && minHeight === 100;
37
+ const isMinFullHeight =
38
+ minHeightUnit === 'vh' &&
39
+ minHeight === 100 &&
40
+ ! attributes?.style?.dimensions?.aspectRatio;
34
41
  const toggleMinFullHeight = () => {
35
42
  if ( isMinFullHeight ) {
36
43
  // If there aren't previous values, take the default ones.
@@ -51,10 +58,17 @@ export default function CoverBlockControls( {
51
58
  setPrevMinHeightValue( minHeight );
52
59
  setPrevMinHeightUnit( minHeightUnit );
53
60
 
54
- // Set full height.
61
+ // Set full height, and clear any aspect ratio value.
55
62
  return setAttributes( {
56
63
  minHeight: 100,
57
64
  minHeightUnit: 'vh',
65
+ style: cleanEmptyObject( {
66
+ ...attributes?.style,
67
+ dimensions: {
68
+ ...attributes?.style?.dimensions,
69
+ aspectRatio: undefined, // Reset aspect ratio when minHeight is set.
70
+ },
71
+ } ),
58
72
  } );
59
73
  };
60
74
 
@@ -308,7 +308,11 @@ export default function CoverInspectorControls( {
308
308
  panelId={ clientId }
309
309
  >
310
310
  <CoverHeightInput
311
- value={ minHeight }
311
+ value={
312
+ attributes?.style?.dimensions?.aspectRatio
313
+ ? ''
314
+ : minHeight
315
+ }
312
316
  unit={ minHeightUnit }
313
317
  onChange={ ( newMinHeight ) =>
314
318
  setAttributes( {
@@ -8,9 +8,10 @@
8
8
  align-items: center;
9
9
  padding: 1em;
10
10
  // Prevent the `wp-block-cover__background` span from overflowing the container when border-radius is applied.
11
+ // `overflow: hidden` is provided as a fallback for browsers that don't support `overflow: clip`.
12
+ overflow: hidden;
11
13
  // Use clip instead of overflow: hidden so that sticky position works on child elements.
12
- // Use overflow-x instead of overflow so that aspect-ratio allows content to expand the area of the cover block.
13
- overflow-x: clip;
14
+ overflow: clip;
14
15
  // This block has customizable padding, border-box makes that more predictable.
15
16
  box-sizing: border-box;
16
17
  // Keep the flex layout direction to the physical direction (LTR) in RTL languages.
@@ -105,7 +105,7 @@ function register_block_core_footnotes_post_meta() {
105
105
  }
106
106
  }
107
107
  }
108
- /**
108
+ /*
109
109
  * Most post types are registered at priority 10, so use priority 20 here in
110
110
  * order to catch them.
111
111
  */
@@ -7,6 +7,7 @@ import { createBlock, getBlockAttributes } from '@wordpress/blocks';
7
7
  * Internal dependencies
8
8
  */
9
9
  import { getLevelFromHeadingNodeName } from './shared';
10
+ import { getTransformedMetadata } from '../utils/get-transformed-metadata';
10
11
 
11
12
  const transforms = {
12
13
  from: [
@@ -15,12 +16,20 @@ const transforms = {
15
16
  isMultiBlock: true,
16
17
  blocks: [ 'core/paragraph' ],
17
18
  transform: ( attributes ) =>
18
- attributes.map( ( { content, anchor, align: textAlign } ) =>
19
- createBlock( 'core/heading', {
20
- content,
21
- anchor,
22
- textAlign,
23
- } )
19
+ attributes.map(
20
+ ( { content, anchor, align: textAlign, metadata } ) =>
21
+ createBlock( 'core/heading', {
22
+ content,
23
+ anchor,
24
+ textAlign,
25
+ metadata: getTransformedMetadata(
26
+ metadata,
27
+ 'core/heading',
28
+ ( { content: contentBinding } ) => ( {
29
+ content: contentBinding,
30
+ } )
31
+ ),
32
+ } )
24
33
  ),
25
34
  },
26
35
  {
@@ -82,8 +91,18 @@ const transforms = {
82
91
  isMultiBlock: true,
83
92
  blocks: [ 'core/paragraph' ],
84
93
  transform: ( attributes ) =>
85
- attributes.map( ( { content, textAlign: align } ) =>
86
- createBlock( 'core/paragraph', { content, align } )
94
+ attributes.map( ( { content, textAlign: align, metadata } ) =>
95
+ createBlock( 'core/paragraph', {
96
+ content,
97
+ align,
98
+ metadata: getTransformedMetadata(
99
+ metadata,
100
+ 'core/paragraph',
101
+ ( { content: contentBinding } ) => ( {
102
+ content: contentBinding,
103
+ } )
104
+ ),
105
+ } )
87
106
  ),
88
107
  },
89
108
  ],