@wordpress/block-library 8.22.0 → 8.24.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 (266) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/block/edit.js +11 -13
  3. package/build/block/edit.js.map +1 -1
  4. package/build/block/edit.native.js +3 -4
  5. package/build/block/edit.native.js.map +1 -1
  6. package/build/button/edit.js +61 -9
  7. package/build/button/edit.js.map +1 -1
  8. package/build/code/transforms.js +20 -7
  9. package/build/code/transforms.js.map +1 -1
  10. package/build/column/edit.js +1 -1
  11. package/build/column/edit.js.map +1 -1
  12. package/build/column/edit.native.js +1 -1
  13. package/build/column/edit.native.js.map +1 -1
  14. package/build/comments/edit/comments-inspector-controls.js +1 -0
  15. package/build/comments/edit/comments-inspector-controls.js.map +1 -1
  16. package/build/cover/edit/index.js +2 -1
  17. package/build/cover/edit/index.js.map +1 -1
  18. package/build/cover/edit/inspector-controls.js +1 -0
  19. package/build/cover/edit/inspector-controls.js.map +1 -1
  20. package/build/details/edit.js +1 -2
  21. package/build/details/edit.js.map +1 -1
  22. package/build/file/edit.js +8 -9
  23. package/build/file/edit.js.map +1 -1
  24. package/build/file/view.js +4 -6
  25. package/build/file/view.js.map +1 -1
  26. package/build/form/index.js +1 -1
  27. package/build/form/index.js.map +1 -1
  28. package/build/form-submit-button/edit.js +2 -1
  29. package/build/form-submit-button/edit.js.map +1 -1
  30. package/build/gallery/gap-styles.js +12 -7
  31. package/build/gallery/gap-styles.js.map +1 -1
  32. package/build/group/edit.js +4 -7
  33. package/build/group/edit.js.map +1 -1
  34. package/build/html/transforms.js +7 -2
  35. package/build/html/transforms.js.map +1 -1
  36. package/build/image/deprecated.js +8 -0
  37. package/build/image/deprecated.js.map +1 -1
  38. package/build/image/edit.js +17 -18
  39. package/build/image/edit.js.map +1 -1
  40. package/build/image/edit.native.js +22 -15
  41. package/build/image/edit.native.js.map +1 -1
  42. package/build/image/image.js +35 -27
  43. package/build/image/image.js.map +1 -1
  44. package/build/image/index.js +2 -3
  45. package/build/image/index.js.map +1 -1
  46. package/build/image/view.js +234 -266
  47. package/build/image/view.js.map +1 -1
  48. package/build/missing/index.js +1 -1
  49. package/build/navigation/edit/overlay-menu-preview.js +1 -1
  50. package/build/navigation/edit/overlay-menu-preview.js.map +1 -1
  51. package/build/navigation/use-template-part-area-label.js +2 -1
  52. package/build/navigation/use-template-part-area-label.js.map +1 -1
  53. package/build/navigation/view.js +153 -176
  54. package/build/navigation/view.js.map +1 -1
  55. package/build/navigation-link/edit.js +1 -1
  56. package/build/navigation-link/edit.js.map +1 -1
  57. package/build/navigation-link/index.js +2 -1
  58. package/build/navigation-link/index.js.map +1 -1
  59. package/build/pattern/edit.js +2 -4
  60. package/build/pattern/edit.js.map +1 -1
  61. package/build/post-author/edit.js +0 -1
  62. package/build/post-author/edit.js.map +1 -1
  63. package/build/post-featured-image/edit.js +21 -6
  64. package/build/post-featured-image/edit.js.map +1 -1
  65. package/build/post-template/edit.js +2 -8
  66. package/build/post-template/edit.js.map +1 -1
  67. package/build/post-template/index.js +1 -1
  68. package/build/post-terms/edit.js +0 -2
  69. package/build/post-terms/edit.js.map +1 -1
  70. package/build/preformatted/transforms.js +1 -4
  71. package/build/preformatted/transforms.js.map +1 -1
  72. package/build/query/edit/query-content.js +1 -0
  73. package/build/query/edit/query-content.js.map +1 -1
  74. package/build/query/view.js +52 -60
  75. package/build/query/view.js.map +1 -1
  76. package/build/quote/index.js +6 -0
  77. package/build/quote/index.js.map +1 -1
  78. package/build/search/view.js +66 -74
  79. package/build/search/view.js.map +1 -1
  80. package/build/template-part/edit/advanced-controls.js +1 -0
  81. package/build/template-part/edit/advanced-controls.js.map +1 -1
  82. package/build/template-part/edit/index.js +3 -7
  83. package/build/template-part/edit/index.js.map +1 -1
  84. package/build/template-part/index.js +6 -2
  85. package/build/template-part/index.js.map +1 -1
  86. package/build/template-part/variations.js +5 -1
  87. package/build/template-part/variations.js.map +1 -1
  88. package/build/utils/remove-anchor-tag.js +17 -0
  89. package/build/utils/remove-anchor-tag.js.map +1 -0
  90. package/build-module/block/edit.js +11 -13
  91. package/build-module/block/edit.js.map +1 -1
  92. package/build-module/block/edit.native.js +3 -4
  93. package/build-module/block/edit.native.js.map +1 -1
  94. package/build-module/button/edit.js +65 -13
  95. package/build-module/button/edit.js.map +1 -1
  96. package/build-module/code/transforms.js +20 -7
  97. package/build-module/code/transforms.js.map +1 -1
  98. package/build-module/column/edit.js +1 -1
  99. package/build-module/column/edit.js.map +1 -1
  100. package/build-module/column/edit.native.js +1 -1
  101. package/build-module/column/edit.native.js.map +1 -1
  102. package/build-module/comments/edit/comments-inspector-controls.js +1 -0
  103. package/build-module/comments/edit/comments-inspector-controls.js.map +1 -1
  104. package/build-module/cover/edit/index.js +2 -1
  105. package/build-module/cover/edit/index.js.map +1 -1
  106. package/build-module/cover/edit/inspector-controls.js +1 -0
  107. package/build-module/cover/edit/inspector-controls.js.map +1 -1
  108. package/build-module/details/edit.js +1 -2
  109. package/build-module/details/edit.js.map +1 -1
  110. package/build-module/file/edit.js +8 -9
  111. package/build-module/file/edit.js.map +1 -1
  112. package/build-module/file/view.js +5 -7
  113. package/build-module/file/view.js.map +1 -1
  114. package/build-module/form/index.js +1 -1
  115. package/build-module/form/index.js.map +1 -1
  116. package/build-module/form-submit-button/edit.js +2 -1
  117. package/build-module/form-submit-button/edit.js.map +1 -1
  118. package/build-module/gallery/gap-styles.js +13 -8
  119. package/build-module/gallery/gap-styles.js.map +1 -1
  120. package/build-module/group/edit.js +4 -7
  121. package/build-module/group/edit.js.map +1 -1
  122. package/build-module/html/transforms.js +7 -2
  123. package/build-module/html/transforms.js.map +1 -1
  124. package/build-module/image/deprecated.js +8 -0
  125. package/build-module/image/deprecated.js.map +1 -1
  126. package/build-module/image/edit.js +18 -19
  127. package/build-module/image/edit.js.map +1 -1
  128. package/build-module/image/edit.native.js +23 -16
  129. package/build-module/image/edit.native.js.map +1 -1
  130. package/build-module/image/image.js +36 -28
  131. package/build-module/image/image.js.map +1 -1
  132. package/build-module/image/index.js +2 -3
  133. package/build-module/image/index.js.map +1 -1
  134. package/build-module/image/view.js +235 -267
  135. package/build-module/image/view.js.map +1 -1
  136. package/build-module/missing/index.js +1 -1
  137. package/build-module/navigation/edit/overlay-menu-preview.js +1 -1
  138. package/build-module/navigation/edit/overlay-menu-preview.js.map +1 -1
  139. package/build-module/navigation/use-template-part-area-label.js +2 -1
  140. package/build-module/navigation/use-template-part-area-label.js.map +1 -1
  141. package/build-module/navigation/view.js +154 -177
  142. package/build-module/navigation/view.js.map +1 -1
  143. package/build-module/navigation-link/edit.js +2 -2
  144. package/build-module/navigation-link/edit.js.map +1 -1
  145. package/build-module/navigation-link/index.js +2 -1
  146. package/build-module/navigation-link/index.js.map +1 -1
  147. package/build-module/pattern/edit.js +2 -4
  148. package/build-module/pattern/edit.js.map +1 -1
  149. package/build-module/post-author/edit.js +0 -1
  150. package/build-module/post-author/edit.js.map +1 -1
  151. package/build-module/post-featured-image/edit.js +21 -6
  152. package/build-module/post-featured-image/edit.js.map +1 -1
  153. package/build-module/post-template/edit.js +2 -8
  154. package/build-module/post-template/edit.js.map +1 -1
  155. package/build-module/post-template/index.js +1 -1
  156. package/build-module/post-terms/edit.js +0 -2
  157. package/build-module/post-terms/edit.js.map +1 -1
  158. package/build-module/preformatted/transforms.js +1 -4
  159. package/build-module/preformatted/transforms.js.map +1 -1
  160. package/build-module/query/edit/query-content.js +1 -0
  161. package/build-module/query/edit/query-content.js.map +1 -1
  162. package/build-module/query/view.js +53 -61
  163. package/build-module/query/view.js.map +1 -1
  164. package/build-module/quote/index.js +6 -0
  165. package/build-module/quote/index.js.map +1 -1
  166. package/build-module/search/view.js +67 -75
  167. package/build-module/search/view.js.map +1 -1
  168. package/build-module/template-part/edit/advanced-controls.js +1 -0
  169. package/build-module/template-part/edit/advanced-controls.js.map +1 -1
  170. package/build-module/template-part/edit/index.js +5 -9
  171. package/build-module/template-part/edit/index.js.map +1 -1
  172. package/build-module/template-part/index.js +6 -2
  173. package/build-module/template-part/index.js.map +1 -1
  174. package/build-module/template-part/variations.js +5 -1
  175. package/build-module/template-part/variations.js.map +1 -1
  176. package/build-module/utils/remove-anchor-tag.js +11 -0
  177. package/build-module/utils/remove-anchor-tag.js.map +1 -0
  178. package/build-style/cover/style-rtl.css +14 -14
  179. package/build-style/cover/style.css +14 -14
  180. package/build-style/editor-rtl.css +15 -6
  181. package/build-style/editor.css +15 -6
  182. package/build-style/gallery/style-rtl.css +28 -0
  183. package/build-style/gallery/style.css +28 -0
  184. package/build-style/image/style-rtl.css +19 -13
  185. package/build-style/image/style.css +19 -13
  186. package/build-style/post-featured-image/editor-rtl.css +9 -0
  187. package/build-style/post-featured-image/editor.css +9 -0
  188. package/build-style/quote/style-rtl.css +3 -0
  189. package/build-style/quote/style.css +3 -0
  190. package/build-style/read-more/style-rtl.css +2 -2
  191. package/build-style/read-more/style.css +2 -2
  192. package/build-style/style-rtl.css +66 -29
  193. package/build-style/style.css +66 -29
  194. package/package.json +32 -32
  195. package/src/block/edit.js +20 -20
  196. package/src/block/edit.native.js +5 -13
  197. package/src/button/edit.js +76 -10
  198. package/src/buttons/test/__snapshots__/edit.native.js.snap +0 -6
  199. package/src/buttons/test/edit.native.js +0 -27
  200. package/src/code/transforms.js +14 -8
  201. package/src/column/edit.js +1 -1
  202. package/src/column/edit.native.js +1 -1
  203. package/src/comments/edit/comments-inspector-controls.js +1 -0
  204. package/src/cover/edit/index.js +1 -0
  205. package/src/cover/edit/inspector-controls.js +1 -0
  206. package/src/cover/style.scss +1 -1
  207. package/src/cover/test/edit.js +1 -1
  208. package/src/details/edit.js +0 -1
  209. package/src/editor.scss +6 -6
  210. package/src/file/edit.js +11 -10
  211. package/src/file/index.php +30 -11
  212. package/src/file/view.js +5 -7
  213. package/src/form/index.js +1 -1
  214. package/src/form-submit-button/edit.js +1 -0
  215. package/src/gallery/gap-styles.js +10 -9
  216. package/src/gallery/style.scss +1 -0
  217. package/src/group/edit.js +4 -11
  218. package/src/heading/test/__snapshots__/index.native.js.snap +6 -0
  219. package/src/heading/test/index.native.js +40 -0
  220. package/src/html/transforms.js +5 -2
  221. package/src/image/block.json +2 -3
  222. package/src/image/deprecated.js +8 -0
  223. package/src/image/edit.js +16 -21
  224. package/src/image/edit.native.js +17 -18
  225. package/src/image/image.js +48 -51
  226. package/src/image/index.php +57 -49
  227. package/src/image/style.scss +18 -13
  228. package/src/image/view.js +281 -324
  229. package/src/missing/block.json +1 -1
  230. package/src/navigation/edit/overlay-menu-preview.js +1 -1
  231. package/src/navigation/index.php +46 -402
  232. package/src/navigation/use-template-part-area-label.js +4 -2
  233. package/src/navigation/view.js +159 -192
  234. package/src/navigation-link/block.json +2 -1
  235. package/src/navigation-link/edit.js +2 -2
  236. package/src/navigation-link/index.php +57 -0
  237. package/src/paragraph/test/__snapshots__/transforms.native.js.snap +6 -0
  238. package/src/paragraph/test/edit.native.js +37 -1
  239. package/src/paragraph/test/transforms.native.js +1 -0
  240. package/src/pattern/edit.js +7 -4
  241. package/src/pattern/index.php +6 -1
  242. package/src/post-author/edit.js +0 -1
  243. package/src/post-featured-image/edit.js +38 -5
  244. package/src/post-featured-image/editor.scss +19 -0
  245. package/src/post-template/block.json +0 -1
  246. package/src/post-template/edit.js +1 -5
  247. package/src/post-terms/edit.js +0 -2
  248. package/src/preformatted/transforms.js +1 -4
  249. package/src/query/edit/query-content.js +1 -0
  250. package/src/query/index.php +42 -24
  251. package/src/query/view.js +58 -65
  252. package/src/query-pagination-next/index.php +3 -3
  253. package/src/query-pagination-numbers/index.php +1 -1
  254. package/src/query-pagination-previous/index.php +3 -3
  255. package/src/quote/block.json +6 -0
  256. package/src/quote/style.scss +4 -0
  257. package/src/read-more/style.scss +1 -1
  258. package/src/search/index.php +40 -40
  259. package/src/search/view.js +58 -63
  260. package/src/template-part/edit/advanced-controls.js +1 -0
  261. package/src/template-part/edit/index.js +7 -14
  262. package/src/template-part/index.js +4 -3
  263. package/src/template-part/index.php +4 -4
  264. package/src/template-part/variations.js +4 -2
  265. package/src/utils/remove-anchor-tag.js +10 -0
  266. package/tsconfig.json +1 -0
package/src/editor.scss CHANGED
@@ -65,7 +65,7 @@
65
65
 
66
66
  // This CSS Custom Properties aren't used anymore as defaults,
67
67
  // but we still need to keep them for backward compatibility.
68
- .editor-styles-wrapper {
68
+ :where(.editor-styles-wrapper) {
69
69
  --wp--preset--font-size--normal: 16px;
70
70
  --wp--preset--font-size--huge: 42px;
71
71
  }
@@ -74,19 +74,19 @@
74
74
  //
75
75
  // The reason we add the editor class wrapper here is
76
76
  // to avoid enqueing the classes twice: here and in ./editor.scss
77
- .editor-styles-wrapper .has-regular-font-size {
77
+ :where(.editor-styles-wrapper) .has-regular-font-size {
78
78
  font-size: 16px;
79
79
  }
80
80
 
81
- .editor-styles-wrapper .has-larger-font-size {
81
+ :where(.editor-styles-wrapper) .has-larger-font-size {
82
82
  font-size: 42px;
83
83
  }
84
84
 
85
- .editor-styles-wrapper .has-normal-font-size {
85
+ :where(.editor-styles-wrapper) .has-normal-font-size {
86
86
  font-size: var(--wp--preset--font-size--normal);
87
87
  }
88
88
 
89
- .editor-styles-wrapper .has-huge-font-size {
89
+ :where(.editor-styles-wrapper) .has-huge-font-size {
90
90
  font-size: var(--wp--preset--font-size--huge);
91
91
  }
92
92
 
@@ -98,6 +98,6 @@
98
98
  */
99
99
 
100
100
  // Remove the browser default border for iframe in Custom HTML block, Embed block, etc.
101
- .editor-styles-wrapper iframe:not([frameborder]) {
101
+ :where(.editor-styles-wrapper) iframe:not([frameborder]) {
102
102
  border: 0;
103
103
  }
package/src/file/edit.js CHANGED
@@ -35,6 +35,7 @@ import { store as noticesStore } from '@wordpress/notices';
35
35
  */
36
36
  import FileBlockInspector from './inspector';
37
37
  import { browserSupportsPdfs } from './utils';
38
+ import removeAnchorTag from '../utils/remove-anchor-tag';
38
39
 
39
40
  export const MIN_PREVIEW_HEIGHT = 200;
40
41
  export const MAX_PREVIEW_HEIGHT = 2000;
@@ -102,7 +103,9 @@ function FileEdit( { attributes, isSelected, setAttributes, clientId } ) {
102
103
  }
103
104
 
104
105
  if ( downloadButtonText === undefined ) {
105
- changeDownloadButtonText( _x( 'Download', 'button label' ) );
106
+ setAttributes( {
107
+ downloadButtonText: _x( 'Download', 'button label' ),
108
+ } );
106
109
  }
107
110
  }, [] );
108
111
 
@@ -148,13 +151,6 @@ function FileEdit( { attributes, isSelected, setAttributes, clientId } ) {
148
151
  setAttributes( { showDownloadButton: newValue } );
149
152
  }
150
153
 
151
- function changeDownloadButtonText( newValue ) {
152
- // Remove anchor tags from button text content.
153
- setAttributes( {
154
- downloadButtonText: newValue.replace( /<\/?a[^>]*>/g, '' ),
155
- } );
156
- }
157
-
158
154
  function changeDisplayPreview( newValue ) {
159
155
  setAttributes( { displayPreview: newValue } );
160
156
  }
@@ -277,7 +273,9 @@ function FileEdit( { attributes, isSelected, setAttributes, clientId } ) {
277
273
  placeholder={ __( 'Write file name…' ) }
278
274
  withoutInteractiveFormatting
279
275
  onChange={ ( text ) =>
280
- setAttributes( { fileName: text } )
276
+ setAttributes( {
277
+ fileName: removeAnchorTag( text ),
278
+ } )
281
279
  }
282
280
  href={ textLinkHref }
283
281
  />
@@ -301,7 +299,10 @@ function FileEdit( { attributes, isSelected, setAttributes, clientId } ) {
301
299
  withoutInteractiveFormatting
302
300
  placeholder={ __( 'Add text…' ) }
303
301
  onChange={ ( text ) =>
304
- changeDownloadButtonText( text )
302
+ setAttributes( {
303
+ downloadButtonText:
304
+ removeAnchorTag( text ),
305
+ } )
305
306
  }
306
307
  />
307
308
  </div>
@@ -15,19 +15,29 @@
15
15
  * @return string Returns the block content.
16
16
  */
17
17
  function render_block_core_file( $attributes, $content, $block ) {
18
+ $is_gutenberg_plugin = defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN;
18
19
  $should_load_view_script = ! empty( $attributes['displayPreview'] );
19
20
  $view_js_file = 'wp-block-file-view';
20
- // If the script already exists, there is no point in removing it from viewScript.
21
- if ( ! wp_script_is( $view_js_file ) ) {
22
- $script_handles = $block->block_type->view_script_handles;
21
+ $script_handles = $block->block_type->view_script_handles;
23
22
 
24
- // If the script is not needed, and it is still in the `view_script_handles`, remove it.
25
- if ( ! $should_load_view_script && in_array( $view_js_file, $script_handles, true ) ) {
26
- $block->block_type->view_script_handles = array_diff( $script_handles, array( $view_js_file ) );
23
+ if ( $is_gutenberg_plugin ) {
24
+ if ( $should_load_view_script ) {
25
+ gutenberg_enqueue_module( '@wordpress/block-library/file-block' );
27
26
  }
28
- // If the script is needed, but it was previously removed, add it again.
29
- if ( $should_load_view_script && ! in_array( $view_js_file, $script_handles, true ) ) {
30
- $block->block_type->view_script_handles = array_merge( $script_handles, array( $view_js_file ) );
27
+ // Remove the view script because we are using the module.
28
+ $block->block_type->view_script_handles = array_diff( $script_handles, array( $view_js_file ) );
29
+ } else {
30
+ // If the script already exists, there is no point in removing it from viewScript.
31
+ if ( ! wp_script_is( $view_js_file ) ) {
32
+
33
+ // If the script is not needed, and it is still in the `view_script_handles`, remove it.
34
+ if ( ! $should_load_view_script && in_array( $view_js_file, $script_handles, true ) ) {
35
+ $block->block_type->view_script_handles = array_diff( $script_handles, array( $view_js_file ) );
36
+ }
37
+ // If the script is needed, but it was previously removed, add it again.
38
+ if ( $should_load_view_script && ! in_array( $view_js_file, $script_handles, true ) ) {
39
+ $block->block_type->view_script_handles = array_merge( $script_handles, array( $view_js_file ) );
40
+ }
31
41
  }
32
42
  }
33
43
 
@@ -57,9 +67,9 @@ function render_block_core_file( $attributes, $content, $block ) {
57
67
  if ( $should_load_view_script ) {
58
68
  $processor = new WP_HTML_Tag_Processor( $content );
59
69
  $processor->next_tag();
60
- $processor->set_attribute( 'data-wp-interactive', '' );
70
+ $processor->set_attribute( 'data-wp-interactive', '{"namespace":"core/file"}' );
61
71
  $processor->next_tag( 'object' );
62
- $processor->set_attribute( 'data-wp-bind--hidden', '!selectors.core.file.hasPdfPreview' );
72
+ $processor->set_attribute( 'data-wp-bind--hidden', '!state.hasPdfPreview' );
63
73
  $processor->set_attribute( 'hidden', true );
64
74
  return $processor->get_updated_html();
65
75
  }
@@ -96,5 +106,14 @@ function register_block_core_file() {
96
106
  'render_callback' => 'render_block_core_file',
97
107
  )
98
108
  );
109
+
110
+ if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) {
111
+ gutenberg_register_module(
112
+ '@wordpress/block-library/file-block',
113
+ gutenberg_url( '/build/interactivity/file.min.js' ),
114
+ array( '@wordpress/interactivity' ),
115
+ defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : get_bloginfo( 'version' )
116
+ );
117
+ }
99
118
  }
100
119
  add_action( 'init', 'register_block_core_file' );
package/src/file/view.js CHANGED
@@ -5,14 +5,12 @@ import { store } from '@wordpress/interactivity';
5
5
  /**
6
6
  * Internal dependencies
7
7
  */
8
- import { browserSupportsPdfs as hasPdfPreview } from './utils';
8
+ import { browserSupportsPdfs } from './utils';
9
9
 
10
- store( {
11
- selectors: {
12
- core: {
13
- file: {
14
- hasPdfPreview,
15
- },
10
+ store( 'core/file', {
11
+ state: {
12
+ get hasPdfPreview() {
13
+ return browserSupportsPdfs();
16
14
  },
17
15
  },
18
16
  } );
package/src/form/index.js CHANGED
@@ -27,7 +27,7 @@ export const init = () => {
27
27
  const DISALLOWED_PARENTS = [ 'core/form' ];
28
28
  addFilter(
29
29
  'blockEditor.__unstableCanInsertBlockType',
30
- 'removeTemplatePartsFromPostTemplates',
30
+ 'core/block-library/preventInsertingFormIntoAnotherForm',
31
31
  (
32
32
  canInsert,
33
33
  blockType,
@@ -14,6 +14,7 @@ const TEMPLATE = [
14
14
  {
15
15
  text: __( 'Submit' ),
16
16
  tagName: 'button',
17
+ type: 'submit',
17
18
  },
18
19
  ],
19
20
  ],
@@ -2,13 +2,18 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import {
5
- BlockList,
6
5
  __experimentalGetGapCSSValue as getGapCSSValue,
6
+ privateApis as blockEditorPrivateApis,
7
7
  } from '@wordpress/block-editor';
8
- import { useContext, createPortal } from '@wordpress/element';
8
+
9
+ /**
10
+ * Internal dependencies
11
+ */
12
+ import { unlock } from '../lock-unlock';
13
+
14
+ const { useStyleOverride } = unlock( blockEditorPrivateApis );
9
15
 
10
16
  export default function GapStyles( { blockGap, clientId } ) {
11
- const styleElement = useContext( BlockList.__unstableElementContext );
12
17
  // --gallery-block--gutter-size is deprecated. --wp--style--gallery-gap-default should be used by themes that want to set a default
13
18
  // gap on the gallery.
14
19
  const fallbackValue = `var( --wp--style--gallery-gap-default, var( --gallery-block--gutter-size, var( --wp--style--block-gap, 0.5em ) ) )`;
@@ -35,11 +40,7 @@ export default function GapStyles( { blockGap, clientId } ) {
35
40
  gap: ${ gapValue }
36
41
  }`;
37
42
 
38
- const GapStyle = () => {
39
- return <style>{ gap }</style>;
40
- };
43
+ useStyleOverride( { css: gap } );
41
44
 
42
- return gap && styleElement
43
- ? createPortal( <GapStyle />, styleElement )
44
- : null;
45
+ return null;
45
46
  }
@@ -57,6 +57,7 @@ figure.wp-block-gallery.has-nested-images {
57
57
  text-align: center;
58
58
  width: 100%;
59
59
  box-sizing: border-box;
60
+ @include custom-scrollbars-on-hover(transparent, rgba($white, 0.8));
60
61
 
61
62
  img {
62
63
  display: inline;
package/src/group/edit.js CHANGED
@@ -52,6 +52,7 @@ function GroupEditControls( { tagName, onSelectTagName } ) {
52
52
  <InspectorControls group="advanced">
53
53
  <SelectControl
54
54
  __nextHasNoMarginBottom
55
+ __next40pxDefaultSize
55
56
  label={ __( 'HTML element' ) }
56
57
  options={ [
57
58
  { label: __( 'Default (<div>)' ), value: 'div' },
@@ -70,13 +71,7 @@ function GroupEditControls( { tagName, onSelectTagName } ) {
70
71
  );
71
72
  }
72
73
 
73
- function GroupEdit( {
74
- attributes,
75
- name,
76
- setAttributes,
77
- clientId,
78
- __unstableLayoutClassNames: layoutClassNames,
79
- } ) {
74
+ function GroupEdit( { attributes, name, setAttributes, clientId } ) {
80
75
  const { hasInnerBlocks, themeSupportsLayout } = useSelect(
81
76
  ( select ) => {
82
77
  const { getBlock, getSettings } = select( blockEditorStore );
@@ -102,9 +97,8 @@ function GroupEdit( {
102
97
  themeSupportsLayout || type === 'flex' || type === 'grid';
103
98
 
104
99
  // Hooks.
105
- const blockProps = useBlockProps( {
106
- className: ! layoutSupportEnabled ? layoutClassNames : null,
107
- } );
100
+ const blockProps = useBlockProps();
101
+
108
102
  const [ showPlaceholder, setShowPlaceholder ] = useShouldShowPlaceHolder( {
109
103
  attributes,
110
104
  usedLayoutType: type,
@@ -133,7 +127,6 @@ function GroupEdit( {
133
127
  templateLock,
134
128
  allowedBlocks,
135
129
  renderAppender,
136
- __unstableDisableLayoutClassNames: ! layoutSupportEnabled,
137
130
  }
138
131
  );
139
132
 
@@ -6,6 +6,12 @@ exports[`Heading block inserts block 1`] = `
6
6
  <!-- /wp:heading -->"
7
7
  `;
8
8
 
9
+ exports[`Heading block should merge with an empty Paragraph block and keep being the Heading block 1`] = `
10
+ "<!-- wp:heading -->
11
+ <h2 class="wp-block-heading">A quick brown fox jumps over the lazy dog.</h2>
12
+ <!-- /wp:heading -->"
13
+ `;
14
+
9
15
  exports[`Heading block should set a background color 1`] = `
10
16
  "<!-- wp:heading {"backgroundColor":"luminous-vivid-orange"} -->
11
17
  <h2 class="wp-block-heading has-luminous-vivid-orange-background-color has-background">A quick brown fox jumps over the lazy dog.</h2>
@@ -17,6 +17,7 @@ import {
17
17
  */
18
18
  import { getBlockTypes, unregisterBlockType } from '@wordpress/blocks';
19
19
  import { registerCoreBlocks } from '@wordpress/block-library';
20
+ import { BACKSPACE, ENTER } from '@wordpress/keycodes';
20
21
 
21
22
  beforeAll( () => {
22
23
  // Register all core blocks
@@ -134,4 +135,43 @@ describe( 'Heading block', () => {
134
135
  )
135
136
  ).toBeVisible();
136
137
  } );
138
+
139
+ it( 'should merge with an empty Paragraph block and keep being the Heading block', async () => {
140
+ // Arrange
141
+ const screen = await initializeEditor();
142
+ await addBlock( screen, 'Paragraph' );
143
+
144
+ // Act
145
+ const paragraphBlock = getBlock( screen, 'Paragraph' );
146
+ fireEvent.press( paragraphBlock );
147
+
148
+ const paragraphTextInput =
149
+ within( paragraphBlock ).getByPlaceholderText( 'Start writing…' );
150
+ fireEvent( paragraphTextInput, 'onKeyDown', {
151
+ nativeEvent: {},
152
+ preventDefault() {},
153
+ keyCode: ENTER,
154
+ } );
155
+
156
+ await addBlock( screen, 'Heading' );
157
+ const headingBlock = getBlock( screen, 'Heading', { rowIndex: 2 } );
158
+ fireEvent.press( headingBlock );
159
+
160
+ const headingTextInput =
161
+ within( headingBlock ).getByPlaceholderText( 'Heading' );
162
+ typeInRichText(
163
+ headingTextInput,
164
+ 'A quick brown fox jumps over the lazy dog.',
165
+ { finalSelectionStart: 0, finalSelectionEnd: 0 }
166
+ );
167
+
168
+ fireEvent( headingTextInput, 'onKeyDown', {
169
+ nativeEvent: {},
170
+ preventDefault() {},
171
+ keyCode: BACKSPACE,
172
+ } );
173
+
174
+ // Assert
175
+ expect( getEditorHtml() ).toMatchSnapshot();
176
+ } );
137
177
  } );
@@ -2,15 +2,18 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { createBlock } from '@wordpress/blocks';
5
+ import { create } from '@wordpress/rich-text';
5
6
 
6
7
  const transforms = {
7
8
  from: [
8
9
  {
9
10
  type: 'block',
10
11
  blocks: [ 'core/code' ],
11
- transform: ( { content } ) => {
12
+ transform: ( { content: html } ) => {
12
13
  return createBlock( 'core/html', {
13
- content,
14
+ // The code block may output HTML formatting, so convert it
15
+ // to plain text.
16
+ content: create( { html } ).text,
14
17
  } );
15
18
  },
16
19
  },
@@ -9,9 +9,6 @@
9
9
  "keywords": [ "img", "photo", "picture" ],
10
10
  "textdomain": "default",
11
11
  "attributes": {
12
- "align": {
13
- "type": "string"
14
- },
15
12
  "url": {
16
13
  "type": "string",
17
14
  "source": "attribute",
@@ -95,6 +92,8 @@
95
92
  }
96
93
  },
97
94
  "supports": {
95
+ "interactivity": true,
96
+ "align": [ "left", "center", "right", "wide", "full" ],
98
97
  "anchor": true,
99
98
  "color": {
100
99
  "text": false,
@@ -1047,6 +1047,14 @@ const v8 = {
1047
1047
  },
1048
1048
  },
1049
1049
  migrate( { width, height, ...attributes } ) {
1050
+ // We need to perform a check here because in cases
1051
+ // where attributes are added dynamically to blocks,
1052
+ // block invalidation overrides the isEligible() method
1053
+ // and forces the migration to run, so it's not guaranteed
1054
+ // that `behaviors` or `behaviors.lightbox` will be defined.
1055
+ if ( ! attributes.behaviors?.lightbox ) {
1056
+ return attributes;
1057
+ }
1050
1058
  const {
1051
1059
  behaviors: {
1052
1060
  lightbox: { enabled },
package/src/image/edit.js CHANGED
@@ -10,8 +10,6 @@ import { getBlobByURL, isBlobURL, revokeBlobURL } from '@wordpress/blob';
10
10
  import { Placeholder } from '@wordpress/components';
11
11
  import { useDispatch, useSelect } from '@wordpress/data';
12
12
  import {
13
- BlockAlignmentControl,
14
- BlockControls,
15
13
  BlockIcon,
16
14
  MediaPlaceholder,
17
15
  useBlockProps,
@@ -106,13 +104,13 @@ export function ImageEdit( {
106
104
  url = '',
107
105
  alt,
108
106
  caption,
109
- align,
110
107
  id,
111
108
  width,
112
109
  height,
113
110
  sizeSlug,
114
111
  aspectRatio,
115
112
  scale,
113
+ align,
116
114
  } = attributes;
117
115
  const [ temporaryURL, setTemporaryURL ] = useState();
118
116
 
@@ -126,6 +124,21 @@ export function ImageEdit( {
126
124
  captionRef.current = caption;
127
125
  }, [ caption ] );
128
126
 
127
+ const { __unstableMarkNextChangeAsNotPersistent } =
128
+ useDispatch( blockEditorStore );
129
+
130
+ useEffect( () => {
131
+ if ( [ 'wide', 'full' ].includes( align ) ) {
132
+ __unstableMarkNextChangeAsNotPersistent();
133
+ setAttributes( {
134
+ width: undefined,
135
+ height: undefined,
136
+ aspectRatio: undefined,
137
+ scale: undefined,
138
+ } );
139
+ }
140
+ }, [ align ] );
141
+
129
142
  const ref = useRef();
130
143
  const { imageDefaultSize, mediaUpload } = useSelect( ( select ) => {
131
144
  const { getSettings } = select( blockEditorStore );
@@ -255,16 +268,6 @@ export function ImageEdit( {
255
268
  }
256
269
  }
257
270
 
258
- function updateAlignment( nextAlign ) {
259
- const extraUpdatedAttributes = [ 'wide', 'full' ].includes( nextAlign )
260
- ? { width: undefined, height: undefined }
261
- : {};
262
- setAttributes( {
263
- ...extraUpdatedAttributes,
264
- align: nextAlign,
265
- } );
266
- }
267
-
268
271
  let isTemp = isTemporaryImage( id, url );
269
272
 
270
273
  // Upload a temporary image on mount.
@@ -375,14 +378,6 @@ export function ImageEdit( {
375
378
  clientId={ clientId }
376
379
  blockEditingMode={ blockEditingMode }
377
380
  />
378
- { ! url && blockEditingMode === 'default' && (
379
- <BlockControls group="block">
380
- <BlockAlignmentControl
381
- value={ align }
382
- onChange={ updateAlignment }
383
- />
384
- </BlockControls>
385
- ) }
386
381
  <MediaPlaceholder
387
382
  icon={ <BlockIcon icon={ icon } /> }
388
383
  onSelect={ onSelectImage }
@@ -44,7 +44,6 @@ import {
44
44
  MEDIA_TYPE_IMAGE,
45
45
  BlockControls,
46
46
  InspectorControls,
47
- BlockAlignmentToolbar,
48
47
  BlockStyles,
49
48
  store as blockEditorStore,
50
49
  blockSettingsScreens,
@@ -212,7 +211,6 @@ export class ImageEdit extends Component {
212
211
  this.onSetFeatured = this.onSetFeatured.bind( this );
213
212
  this.onFocusCaption = this.onFocusCaption.bind( this );
214
213
  this.onSelectURL = this.onSelectURL.bind( this );
215
- this.updateAlignment = this.updateAlignment.bind( this );
216
214
  this.accessibilityLabelCreator =
217
215
  this.accessibilityLabelCreator.bind( this );
218
216
  this.setMappedAttributes = this.setMappedAttributes.bind( this );
@@ -305,6 +303,20 @@ export class ImageEdit extends Component {
305
303
  this.replacedFeaturedImage = false;
306
304
  setFeaturedImage( id );
307
305
  }
306
+
307
+ const { align } = attributes;
308
+ const { __unstableMarkNextChangeAsNotPersistent } = this.props;
309
+
310
+ // Update the attributes if the align is wide or full
311
+ if ( [ 'wide', 'full' ].includes( align ) ) {
312
+ __unstableMarkNextChangeAsNotPersistent();
313
+ setAttributes( {
314
+ width: undefined,
315
+ height: undefined,
316
+ aspectRatio: undefined,
317
+ scale: undefined,
318
+ } );
319
+ }
308
320
  }
309
321
 
310
322
  static getDerivedStateFromProps( props, state ) {
@@ -391,18 +403,6 @@ export class ImageEdit extends Component {
391
403
  } );
392
404
  }
393
405
 
394
- updateAlignment( nextAlign ) {
395
- const extraUpdatedAttributes = Object.values(
396
- WIDE_ALIGNMENTS.alignments
397
- ).includes( nextAlign )
398
- ? { width: undefined, height: undefined }
399
- : {};
400
- this.props.setAttributes( {
401
- ...extraUpdatedAttributes,
402
- align: nextAlign,
403
- } );
404
- }
405
-
406
406
  onSetNewTab( value ) {
407
407
  const updatedLinkTarget = getUpdatedLinkTargetSettings(
408
408
  value,
@@ -711,10 +711,6 @@ export class ImageEdit extends Component {
711
711
  onClick={ open }
712
712
  />
713
713
  </ToolbarGroup>
714
- <BlockAlignmentToolbar
715
- value={ align }
716
- onChange={ this.updateAlignment }
717
- />
718
714
  </BlockControls>
719
715
  );
720
716
 
@@ -941,8 +937,11 @@ export default compose( [
941
937
  } ),
942
938
  withDispatch( ( dispatch ) => {
943
939
  const { createErrorNotice } = dispatch( noticesStore );
940
+ const { __unstableMarkNextChangeAsNotPersistent } =
941
+ dispatch( blockEditorStore );
944
942
 
945
943
  return {
944
+ __unstableMarkNextChangeAsNotPersistent,
946
945
  createErrorNotice,
947
946
  closeSettingsBottomSheet() {
948
947
  dispatch( editPostStore ).closeGeneralSidebar();