@wordpress/block-library 7.1.1 → 7.2.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 (304) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/build/avatar/edit.js +205 -0
  3. package/build/avatar/edit.js.map +1 -0
  4. package/build/avatar/hooks.js +111 -0
  5. package/build/avatar/hooks.js.map +1 -0
  6. package/build/avatar/index.js +83 -0
  7. package/build/avatar/index.js.map +1 -0
  8. package/build/avatar/user-control.js +63 -0
  9. package/build/avatar/user-control.js.map +1 -0
  10. package/build/column/index.js +2 -1
  11. package/build/column/index.js.map +1 -1
  12. package/build/comment-author-avatar/index.js +1 -0
  13. package/build/comment-author-avatar/index.js.map +1 -1
  14. package/build/comment-date/edit.js +10 -25
  15. package/build/comment-date/edit.js.map +1 -1
  16. package/build/comment-template/edit.js +79 -52
  17. package/build/comment-template/edit.js.map +1 -1
  18. package/build/cover/edit.js +23 -33
  19. package/build/cover/edit.js.map +1 -1
  20. package/build/embed/variations.js +2 -2
  21. package/build/embed/variations.js.map +1 -1
  22. package/build/gallery/edit.js +18 -5
  23. package/build/gallery/edit.js.map +1 -1
  24. package/build/gallery/gallery.js +1 -1
  25. package/build/gallery/gallery.js.map +1 -1
  26. package/build/gallery/gap-styles.js +29 -0
  27. package/build/gallery/gap-styles.js.map +1 -0
  28. package/build/gallery/index.js +17 -1
  29. package/build/gallery/index.js.map +1 -1
  30. package/build/group/index.js +3 -1
  31. package/build/group/index.js.map +1 -1
  32. package/build/group/variations.js +1 -2
  33. package/build/group/variations.js.map +1 -1
  34. package/build/image/image.js +3 -1
  35. package/build/image/image.js.map +1 -1
  36. package/build/index.js +8 -2
  37. package/build/index.js.map +1 -1
  38. package/build/list/index.js +5 -7
  39. package/build/list/index.js.map +1 -1
  40. package/build/list/v2/edit.js +85 -0
  41. package/build/list/v2/edit.js.map +1 -0
  42. package/build/list/v2/index.js +33 -0
  43. package/build/list/v2/index.js.map +1 -0
  44. package/build/list/v2/save.js +34 -0
  45. package/build/list/v2/save.js.map +1 -0
  46. package/build/list/v2/transforms.js +121 -0
  47. package/build/list/v2/transforms.js.map +1 -0
  48. package/build/list-item/edit.js +47 -0
  49. package/build/list-item/edit.js.map +1 -0
  50. package/build/list-item/index.js +67 -0
  51. package/build/list-item/index.js.map +1 -0
  52. package/build/list-item/save.js +23 -0
  53. package/build/list-item/save.js.map +1 -0
  54. package/build/media-text/edit.js +3 -1
  55. package/build/media-text/edit.js.map +1 -1
  56. package/build/navigation/use-navigation-entities.js +26 -54
  57. package/build/navigation/use-navigation-entities.js.map +1 -1
  58. package/build/navigation-link/edit.js +88 -34
  59. package/build/navigation-link/edit.js.map +1 -1
  60. package/build/post-date/edit.js +31 -37
  61. package/build/post-date/edit.js.map +1 -1
  62. package/build/post-featured-image/edit.js +2 -1
  63. package/build/post-featured-image/edit.js.map +1 -1
  64. package/build/pullquote/edit.js +5 -3
  65. package/build/pullquote/edit.js.map +1 -1
  66. package/build/query/variations.js +4 -4
  67. package/build/query/variations.js.map +1 -1
  68. package/build/query-no-results/edit.js +28 -0
  69. package/build/query-no-results/edit.js.map +1 -0
  70. package/build/query-no-results/index.js +54 -0
  71. package/build/query-no-results/index.js.map +1 -0
  72. package/build/query-no-results/save.js +18 -0
  73. package/build/query-no-results/save.js.map +1 -0
  74. package/build/search/edit.js +2 -3
  75. package/build/search/edit.js.map +1 -1
  76. package/build/separator/deprecated.js +83 -0
  77. package/build/separator/deprecated.js.map +1 -0
  78. package/build/separator/edit.js +31 -23
  79. package/build/separator/edit.js.map +1 -1
  80. package/build/separator/index.js +17 -7
  81. package/build/separator/index.js.map +1 -1
  82. package/build/separator/save.js +18 -13
  83. package/build/separator/save.js.map +1 -1
  84. package/build/separator/use-deprecated-opacity.js +39 -0
  85. package/build/separator/use-deprecated-opacity.js.map +1 -0
  86. package/build/social-links/edit.js +14 -3
  87. package/build/social-links/edit.js.map +1 -1
  88. package/build/social-links/index.js +1 -1
  89. package/build/spacer/controls.js +6 -16
  90. package/build/spacer/controls.js.map +1 -1
  91. package/build/spacer/controls.native.js +3 -1
  92. package/build/spacer/controls.native.js.map +1 -1
  93. package/build/spacer/edit.js +4 -5
  94. package/build/spacer/edit.js.map +1 -1
  95. package/build/table/deprecated.js +1 -1
  96. package/build/table/deprecated.js.map +1 -1
  97. package/build/tag-cloud/edit.js +58 -2
  98. package/build/tag-cloud/edit.js.map +1 -1
  99. package/build/tag-cloud/index.js +8 -0
  100. package/build/tag-cloud/index.js.map +1 -1
  101. package/build-module/avatar/edit.js +190 -0
  102. package/build-module/avatar/edit.js.map +1 -0
  103. package/build-module/avatar/hooks.js +99 -0
  104. package/build-module/avatar/hooks.js.map +1 -0
  105. package/build-module/avatar/index.js +70 -0
  106. package/build-module/avatar/index.js.map +1 -0
  107. package/build-module/avatar/user-control.js +52 -0
  108. package/build-module/avatar/user-control.js.map +1 -0
  109. package/build-module/column/index.js +2 -1
  110. package/build-module/column/index.js.map +1 -1
  111. package/build-module/comment-author-avatar/index.js +1 -0
  112. package/build-module/comment-author-avatar/index.js.map +1 -1
  113. package/build-module/comment-date/edit.js +13 -30
  114. package/build-module/comment-date/edit.js.map +1 -1
  115. package/build-module/comment-template/edit.js +79 -52
  116. package/build-module/comment-template/edit.js.map +1 -1
  117. package/build-module/cover/edit.js +23 -34
  118. package/build-module/cover/edit.js.map +1 -1
  119. package/build-module/embed/variations.js +2 -2
  120. package/build-module/embed/variations.js.map +1 -1
  121. package/build-module/gallery/edit.js +17 -5
  122. package/build-module/gallery/edit.js.map +1 -1
  123. package/build-module/gallery/gallery.js +1 -1
  124. package/build-module/gallery/gallery.js.map +1 -1
  125. package/build-module/gallery/gap-styles.js +22 -0
  126. package/build-module/gallery/gap-styles.js.map +1 -0
  127. package/build-module/gallery/index.js +17 -1
  128. package/build-module/gallery/index.js.map +1 -1
  129. package/build-module/group/index.js +3 -1
  130. package/build-module/group/index.js.map +1 -1
  131. package/build-module/group/variations.js +1 -2
  132. package/build-module/group/variations.js.map +1 -1
  133. package/build-module/image/image.js +3 -1
  134. package/build-module/image/image.js.map +1 -1
  135. package/build-module/index.js +5 -2
  136. package/build-module/index.js.map +1 -1
  137. package/build-module/list/index.js +5 -1
  138. package/build-module/list/index.js.map +1 -1
  139. package/build-module/list/v2/edit.js +69 -0
  140. package/build-module/list/v2/edit.js.map +1 -0
  141. package/build-module/list/v2/index.js +19 -0
  142. package/build-module/list/v2/index.js.map +1 -0
  143. package/build-module/list/v2/save.js +23 -0
  144. package/build-module/list/v2/save.js.map +1 -0
  145. package/build-module/list/v2/transforms.js +111 -0
  146. package/build-module/list/v2/transforms.js.map +1 -0
  147. package/build-module/list-item/edit.js +37 -0
  148. package/build-module/list-item/edit.js.map +1 -0
  149. package/build-module/list-item/index.js +53 -0
  150. package/build-module/list-item/index.js.map +1 -0
  151. package/build-module/list-item/save.js +15 -0
  152. package/build-module/list-item/save.js.map +1 -0
  153. package/build-module/media-text/edit.js +3 -1
  154. package/build-module/media-text/edit.js.map +1 -1
  155. package/build-module/navigation/use-navigation-entities.js +27 -54
  156. package/build-module/navigation/use-navigation-entities.js.map +1 -1
  157. package/build-module/navigation-link/edit.js +88 -33
  158. package/build-module/navigation-link/edit.js.map +1 -1
  159. package/build-module/post-date/edit.js +32 -43
  160. package/build-module/post-date/edit.js.map +1 -1
  161. package/build-module/post-featured-image/edit.js +2 -1
  162. package/build-module/post-featured-image/edit.js.map +1 -1
  163. package/build-module/pullquote/edit.js +6 -3
  164. package/build-module/pullquote/edit.js.map +1 -1
  165. package/build-module/query/variations.js +4 -4
  166. package/build-module/query/variations.js.map +1 -1
  167. package/build-module/query-no-results/edit.js +18 -0
  168. package/build-module/query-no-results/edit.js.map +1 -0
  169. package/build-module/query-no-results/index.js +40 -0
  170. package/build-module/query-no-results/index.js.map +1 -0
  171. package/build-module/query-no-results/save.js +10 -0
  172. package/build-module/query-no-results/save.js.map +1 -0
  173. package/build-module/search/edit.js +2 -3
  174. package/build-module/search/edit.js.map +1 -1
  175. package/build-module/separator/deprecated.js +70 -0
  176. package/build-module/separator/deprecated.js.map +1 -0
  177. package/build-module/separator/edit.js +31 -22
  178. package/build-module/separator/edit.js.map +1 -1
  179. package/build-module/separator/index.js +16 -7
  180. package/build-module/separator/index.js.map +1 -1
  181. package/build-module/separator/save.js +19 -14
  182. package/build-module/separator/save.js.map +1 -1
  183. package/build-module/separator/use-deprecated-opacity.js +30 -0
  184. package/build-module/separator/use-deprecated-opacity.js.map +1 -0
  185. package/build-module/social-links/edit.js +15 -4
  186. package/build-module/social-links/edit.js.map +1 -1
  187. package/build-module/social-links/index.js +1 -1
  188. package/build-module/spacer/controls.js +8 -19
  189. package/build-module/spacer/controls.js.map +1 -1
  190. package/build-module/spacer/controls.native.js +2 -1
  191. package/build-module/spacer/controls.native.js.map +1 -1
  192. package/build-module/spacer/edit.js +3 -3
  193. package/build-module/spacer/edit.js.map +1 -1
  194. package/build-module/table/deprecated.js +1 -1
  195. package/build-module/table/deprecated.js.map +1 -1
  196. package/build-module/tag-cloud/edit.js +60 -4
  197. package/build-module/tag-cloud/edit.js.map +1 -1
  198. package/build-module/tag-cloud/index.js +8 -0
  199. package/build-module/tag-cloud/index.js.map +1 -1
  200. package/build-style/avatar/editor-rtl.css +79 -0
  201. package/build-style/avatar/editor.css +79 -0
  202. package/build-style/editor-rtl.css +23 -2
  203. package/build-style/editor.css +23 -2
  204. package/build-style/gallery/editor-rtl.css +0 -1
  205. package/build-style/gallery/editor.css +0 -1
  206. package/build-style/gallery/style-rtl.css +102 -169
  207. package/build-style/gallery/style.css +102 -169
  208. package/build-style/image/style-rtl.css +2 -0
  209. package/build-style/image/style.css +2 -0
  210. package/build-style/navigation-link/editor-rtl.css +13 -0
  211. package/build-style/navigation-link/editor.css +13 -0
  212. package/build-style/pullquote/style-rtl.css +0 -4
  213. package/build-style/pullquote/style.css +0 -4
  214. package/build-style/separator/editor-rtl.css +3 -0
  215. package/build-style/separator/editor.css +3 -0
  216. package/build-style/separator/theme-rtl.css +7 -1
  217. package/build-style/separator/theme.css +7 -1
  218. package/build-style/site-logo/editor-rtl.css +3 -1
  219. package/build-style/site-logo/editor.css +3 -1
  220. package/build-style/style-rtl.css +104 -173
  221. package/build-style/style.css +104 -173
  222. package/build-style/theme-rtl.css +7 -1
  223. package/build-style/theme.css +7 -1
  224. package/package.json +28 -28
  225. package/src/avatar/block.json +53 -0
  226. package/src/avatar/edit.js +222 -0
  227. package/src/avatar/editor.scss +3 -0
  228. package/src/avatar/hooks.js +96 -0
  229. package/src/avatar/index.js +18 -0
  230. package/src/avatar/index.php +146 -0
  231. package/src/avatar/user-control.js +56 -0
  232. package/src/column/block.json +2 -1
  233. package/src/comment-author-avatar/block.json +1 -0
  234. package/src/comment-date/edit.js +20 -30
  235. package/src/comment-template/edit.js +65 -44
  236. package/src/cover/edit.js +26 -31
  237. package/src/editor.scss +1 -0
  238. package/src/embed/variations.js +2 -2
  239. package/src/gallery/block.json +17 -1
  240. package/src/gallery/deprecated.scss +2 -2
  241. package/src/gallery/edit.js +15 -8
  242. package/src/gallery/editor.scss +0 -1
  243. package/src/gallery/gallery.js +8 -7
  244. package/src/gallery/gap-styles.js +21 -0
  245. package/src/gallery/index.php +42 -1
  246. package/src/gallery/style.scss +11 -44
  247. package/src/group/block.json +3 -1
  248. package/src/group/variations.js +1 -1
  249. package/src/image/image.js +4 -1
  250. package/src/image/style.scss +3 -0
  251. package/src/index.js +6 -1
  252. package/src/list/index.js +6 -1
  253. package/src/list/v2/edit.js +77 -0
  254. package/src/list/v2/index.js +20 -0
  255. package/src/list/v2/save.js +18 -0
  256. package/src/list/v2/transforms.js +116 -0
  257. package/src/list-item/block.json +26 -0
  258. package/src/list-item/edit.js +47 -0
  259. package/src/list-item/index.js +27 -0
  260. package/src/list-item/save.js +13 -0
  261. package/src/media-text/edit.js +1 -1
  262. package/src/navigation/index.php +22 -2
  263. package/src/navigation/use-navigation-entities.js +37 -73
  264. package/src/navigation-link/edit.js +145 -61
  265. package/src/navigation-link/editor.scss +11 -0
  266. package/src/post-date/edit.js +63 -52
  267. package/src/post-date/index.php +1 -1
  268. package/src/post-date/test/edit.js +17 -0
  269. package/src/post-featured-image/edit.js +9 -1
  270. package/src/post-featured-image/index.php +2 -1
  271. package/src/pullquote/edit.js +4 -3
  272. package/src/pullquote/style.scss +0 -5
  273. package/src/query/variations.js +4 -0
  274. package/src/query-no-results/block.json +20 -0
  275. package/src/query-no-results/edit.js +28 -0
  276. package/src/query-no-results/index.js +20 -0
  277. package/src/query-no-results/index.php +59 -0
  278. package/src/query-no-results/save.js +8 -0
  279. package/src/search/edit.js +1 -2
  280. package/src/separator/block.json +13 -6
  281. package/src/separator/deprecated.js +57 -0
  282. package/src/separator/deprecated.scss +6 -0
  283. package/src/separator/edit.js +36 -14
  284. package/src/separator/editor.scss +6 -0
  285. package/src/separator/index.js +2 -0
  286. package/src/separator/save.js +22 -14
  287. package/src/separator/test/edit.js +113 -0
  288. package/src/separator/theme.scss +7 -1
  289. package/src/separator/use-deprecated-opacity.js +41 -0
  290. package/src/site-logo/editor.scss +3 -1
  291. package/src/social-links/block.json +1 -1
  292. package/src/social-links/edit.js +15 -5
  293. package/src/spacer/controls.js +12 -18
  294. package/src/spacer/controls.native.js +2 -1
  295. package/src/spacer/edit.js +3 -6
  296. package/src/table/deprecated.js +5 -1
  297. package/src/tag-cloud/block.json +8 -0
  298. package/src/tag-cloud/edit.js +82 -2
  299. package/src/tag-cloud/index.php +6 -0
  300. package/build/separator/separator-settings.js +0 -36
  301. package/build/separator/separator-settings.js.map +0 -1
  302. package/build-module/separator/separator-settings.js +0 -27
  303. package/build-module/separator/separator-settings.js.map +0 -1
  304. package/src/separator/separator-settings.js +0 -24
@@ -46,11 +46,6 @@
46
46
  text-align: right;
47
47
  }
48
48
 
49
- // .is-style-solid-color is deprecated.
50
- .wp-block-pullquote:not(.is-style-solid-color) {
51
- background: none;
52
- }
53
-
54
49
  // .is-style-solid-color is deprecated.
55
50
  .wp-block-pullquote.is-style-solid-color {
56
51
  border: none;
@@ -66,6 +66,7 @@ const variations = [
66
66
  [ [ 'core/post-title' ], [ 'core/post-date' ] ],
67
67
  ],
68
68
  [ 'core/query-pagination' ],
69
+ [ 'core/query-no-results' ],
69
70
  ],
70
71
  scope: [ 'block' ],
71
72
  },
@@ -81,6 +82,7 @@ const variations = [
81
82
  [ [ 'core/post-title' ], [ 'core/post-excerpt' ] ],
82
83
  ],
83
84
  [ 'core/query-pagination' ],
85
+ [ 'core/query-no-results' ],
84
86
  ],
85
87
  scope: [ 'block' ],
86
88
  },
@@ -100,6 +102,7 @@ const variations = [
100
102
  ],
101
103
  ],
102
104
  [ 'core/query-pagination' ],
105
+ [ 'core/query-no-results' ],
103
106
  ],
104
107
  scope: [ 'block' ],
105
108
  },
@@ -119,6 +122,7 @@ const variations = [
119
122
  ],
120
123
  ],
121
124
  [ 'core/query-pagination' ],
125
+ [ 'core/query-no-results' ],
122
126
  ],
123
127
  scope: [ 'block' ],
124
128
  },
@@ -0,0 +1,20 @@
1
+ {
2
+ "$schema": "https://schemas.wp.org/trunk/block.json",
3
+ "apiVersion": 2,
4
+ "name": "core/query-no-results",
5
+ "title": "No results",
6
+ "category": "theme",
7
+ "description": "Contains the block elements used to render content when no query results are found.",
8
+ "parent": [ "core/query" ],
9
+ "textdomain": "default",
10
+ "usesContext": [ "queryId", "query" ],
11
+ "supports": {
12
+ "align": true,
13
+ "reusable": false,
14
+ "html": false,
15
+ "color": {
16
+ "gradients": true,
17
+ "link": true
18
+ }
19
+ }
20
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';
5
+ import { __ } from '@wordpress/i18n';
6
+
7
+ const TEMPLATE = [
8
+ [
9
+ 'core/paragraph',
10
+ {
11
+ placeholder: __(
12
+ 'Add a text or blocks that will display when the query returns no results.'
13
+ ),
14
+ },
15
+ ],
16
+ ];
17
+
18
+ export default function QueryNoResultsEdit() {
19
+ const blockProps = useBlockProps();
20
+ const innerBlocksProps = useInnerBlocksProps( blockProps, {
21
+ template: TEMPLATE,
22
+ } );
23
+ return (
24
+ <>
25
+ <div { ...innerBlocksProps } />
26
+ </>
27
+ );
28
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { loop as icon } from '@wordpress/icons';
5
+
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+ import metadata from './block.json';
10
+ import edit from './edit';
11
+ import save from './save';
12
+
13
+ const { name } = metadata;
14
+ export { metadata, name };
15
+
16
+ export const settings = {
17
+ icon,
18
+ edit,
19
+ save,
20
+ };
@@ -0,0 +1,59 @@
1
+ <?php
2
+ /**
3
+ * Server-side rendering of the `core/query-no-results` block.
4
+ *
5
+ * @package WordPress
6
+ */
7
+
8
+ /**
9
+ * Renders the `core/query-no-results` block on the server.
10
+ *
11
+ * @param array $attributes Block attributes.
12
+ * @param string $content Block default content.
13
+ * @param WP_Block $block Block instance.
14
+ *
15
+ * @return string Returns the wrapper for the no results block.
16
+ */
17
+ function render_block_core_query_no_results( $attributes, $content, $block ) {
18
+ if ( empty( trim( $content ) ) ) {
19
+ return '';
20
+ }
21
+
22
+ $page_key = isset( $block->context['queryId'] ) ? 'query-' . $block->context['queryId'] . '-page' : 'query-page';
23
+ $page = empty( $_GET[ $page_key ] ) ? 1 : (int) $_GET[ $page_key ];
24
+ $query_args = build_query_vars_from_query_block( $block, $page );
25
+ // Override the custom query with the global query if needed.
26
+ $use_global_query = ( isset( $block->context['query']['inherit'] ) && $block->context['query']['inherit'] );
27
+ if ( $use_global_query ) {
28
+ global $wp_query;
29
+ if ( $wp_query && isset( $wp_query->query_vars ) && is_array( $wp_query->query_vars ) ) {
30
+ $query_args = wp_parse_args( $wp_query->query_vars, $query_args );
31
+ }
32
+ }
33
+ $query = new WP_Query( $query_args );
34
+
35
+ if ( $query->have_posts() ) {
36
+ return '';
37
+ }
38
+
39
+ wp_reset_postdata();
40
+
41
+ return sprintf(
42
+ '<div %1$s>%2$s</div>',
43
+ get_block_wrapper_attributes(),
44
+ $content
45
+ );
46
+ }
47
+
48
+ /**
49
+ * Registers the `core/query-no-results` block on the server.
50
+ */
51
+ function register_block_core_query_no_results() {
52
+ register_block_type_from_metadata(
53
+ __DIR__ . '/query-no-results',
54
+ array(
55
+ 'render_callback' => 'render_block_core_query_no_results',
56
+ )
57
+ );
58
+ }
59
+ add_action( 'init', 'register_block_core_query_no_results' );
@@ -0,0 +1,8 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { InnerBlocks } from '@wordpress/block-editor';
5
+
6
+ export default function QueryNoResultsSave() {
7
+ return <InnerBlocks.Content />;
8
+ }
@@ -12,7 +12,6 @@ import {
12
12
  InspectorControls,
13
13
  RichText,
14
14
  __experimentalUseBorderProps as useBorderProps,
15
- __experimentalUnitControl as UnitControl,
16
15
  __experimentalUseColorProps as useColorProps,
17
16
  store as blockEditorStore,
18
17
  } from '@wordpress/block-editor';
@@ -28,6 +27,7 @@ import {
28
27
  PanelBody,
29
28
  BaseControl,
30
29
  __experimentalUseCustomUnits as useCustomUnits,
30
+ __experimentalUnitControl as UnitControl,
31
31
  } from '@wordpress/components';
32
32
  import { useInstanceId } from '@wordpress/compose';
33
33
  import { Icon, search } from '@wordpress/icons';
@@ -352,7 +352,6 @@ export default function SearchEdit( {
352
352
  } }
353
353
  style={ { maxWidth: 80 } }
354
354
  value={ `${ width }${ widthUnit }` }
355
- unit={ widthUnit }
356
355
  units={ units }
357
356
  />
358
357
 
@@ -8,16 +8,23 @@
8
8
  "keywords": [ "horizontal-line", "hr", "divider" ],
9
9
  "textdomain": "default",
10
10
  "attributes": {
11
- "color": {
12
- "type": "string"
13
- },
14
- "customColor": {
15
- "type": "string"
11
+ "opacity": {
12
+ "type": "string",
13
+ "default": "alpha-channel"
16
14
  }
17
15
  },
18
16
  "supports": {
19
17
  "anchor": true,
20
- "align": [ "center", "wide", "full" ]
18
+ "align": [ "center", "wide", "full" ],
19
+ "color": {
20
+ "__experimentalSkipSerialization": true,
21
+ "gradients": true,
22
+ "background": true,
23
+ "text": false,
24
+ "__experimentalDefaultControls": {
25
+ "background": true
26
+ }
27
+ }
21
28
  },
22
29
  "styles": [
23
30
  { "name": "default", "label": "Default", "isDefault": true },
@@ -0,0 +1,57 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import classnames from 'classnames';
5
+ import { omit } from 'lodash';
6
+
7
+ /**
8
+ * WordPress dependencies
9
+ */
10
+ import { getColorClassName, useBlockProps } from '@wordpress/block-editor';
11
+
12
+ const v1 = {
13
+ attributes: {
14
+ color: {
15
+ type: 'string',
16
+ },
17
+ customColor: {
18
+ type: 'string',
19
+ },
20
+ },
21
+ save( { attributes } ) {
22
+ const { color, customColor } = attributes;
23
+
24
+ // the hr support changing color using border-color, since border-color
25
+ // is not yet supported in the color palette, we use background-color
26
+ const backgroundClass = getColorClassName( 'background-color', color );
27
+ // the dots styles uses text for the dots, to change those dots color is
28
+ // using color, not backgroundColor
29
+ const colorClass = getColorClassName( 'color', color );
30
+
31
+ const className = classnames( {
32
+ 'has-text-color has-background': color || customColor,
33
+ [ backgroundClass ]: backgroundClass,
34
+ [ colorClass ]: colorClass,
35
+ } );
36
+
37
+ const style = {
38
+ backgroundColor: backgroundClass ? undefined : customColor,
39
+ color: colorClass ? undefined : customColor,
40
+ };
41
+
42
+ return <hr { ...useBlockProps.save( { className, style } ) } />;
43
+ },
44
+ migrate( attributes ) {
45
+ const { color, customColor } = attributes;
46
+ return {
47
+ ...omit( attributes, [ 'color', 'customColor' ] ),
48
+ backgroundColor: color ? color : undefined,
49
+ opacity: 'css',
50
+ style: customColor
51
+ ? { color: { background: customColor } }
52
+ : undefined,
53
+ };
54
+ },
55
+ };
56
+
57
+ export default [ v1 ];
@@ -0,0 +1,6 @@
1
+ .wp-block-separator {
2
+ // V1 version of the block expects a default opactiy of 0.4 to be set.
3
+ &.has-css-opacity {
4
+ opacity: 0.4;
5
+ }
6
+ }
@@ -7,30 +7,52 @@ import classnames from 'classnames';
7
7
  * WordPress dependencies
8
8
  */
9
9
  import { HorizontalRule } from '@wordpress/components';
10
- import { withColors, useBlockProps } from '@wordpress/block-editor';
10
+ import {
11
+ useBlockProps,
12
+ getColorClassName,
13
+ __experimentalUseColorProps as useColorProps,
14
+ } from '@wordpress/block-editor';
15
+
11
16
  /**
12
17
  * Internal dependencies
13
18
  */
14
- import SeparatorSettings from './separator-settings';
19
+ import useDeprecatedOpacity from './use-deprecated-opacity';
20
+
21
+ export default function SeparatorEdit( { attributes, setAttributes } ) {
22
+ const { backgroundColor, opacity, style } = attributes;
23
+ const colorProps = useColorProps( attributes );
24
+ const currentColor = colorProps?.style?.backgroundColor;
25
+ const hasCustomColor = !! style?.color?.background;
26
+
27
+ useDeprecatedOpacity( opacity, currentColor, setAttributes );
28
+
29
+ // The dots styles uses text for the dots, to change those dots color is
30
+ // using color, not backgroundColor.
31
+ const colorClass = getColorClassName( 'color', backgroundColor );
32
+
33
+ const className = classnames(
34
+ {
35
+ 'has-text-color': backgroundColor || currentColor,
36
+ [ colorClass ]: colorClass,
37
+ 'has-css-opacity': opacity === 'css',
38
+ 'has-alpha-channel-opacity': opacity === 'alpha-channel',
39
+ },
40
+ colorProps.classname
41
+ );
42
+
43
+ const styles = {
44
+ color: currentColor,
45
+ backgroundColor: currentColor,
46
+ };
15
47
 
16
- function SeparatorEdit( { color, setColor, className } ) {
17
48
  return (
18
49
  <>
19
50
  <HorizontalRule
20
51
  { ...useBlockProps( {
21
- className: classnames( className, {
22
- 'has-background': color.color,
23
- [ color.class ]: color.class,
24
- } ),
25
- style: {
26
- backgroundColor: color.color,
27
- color: color.color,
28
- },
52
+ className,
53
+ style: hasCustomColor ? styles : undefined,
29
54
  } ) }
30
55
  />
31
- <SeparatorSettings color={ color } setColor={ setColor } />
32
56
  </>
33
57
  );
34
58
  }
35
-
36
- export default withColors( 'color', { textColor: 'color' } )( SeparatorEdit );
@@ -2,4 +2,10 @@
2
2
  // Prevent margin collapsing so the area to select the separator is bigger.
3
3
  padding-top: 0.1px;
4
4
  padding-bottom: 0.1px;
5
+
6
+ // This is also set in style.scss, but needs a higher specificity in editor
7
+ // due to the way that color block supports adds additional background color styles.
8
+ &.wp-block-separator.is-style-dots {
9
+ background: none !important;
10
+ }
5
11
  }
@@ -10,6 +10,7 @@ import edit from './edit';
10
10
  import metadata from './block.json';
11
11
  import save from './save';
12
12
  import transforms from './transforms';
13
+ import deprecated from './deprecated';
13
14
 
14
15
  const { name } = metadata;
15
16
 
@@ -26,4 +27,5 @@ export const settings = {
26
27
  transforms,
27
28
  edit,
28
29
  save,
30
+ deprecated,
29
31
  };
@@ -6,28 +6,36 @@ import classnames from 'classnames';
6
6
  /**
7
7
  * WordPress dependencies
8
8
  */
9
- import { getColorClassName, useBlockProps } from '@wordpress/block-editor';
9
+ import {
10
+ getColorClassName,
11
+ useBlockProps,
12
+ __experimentalGetColorClassesAndStyles as getColorClassesAndStyles,
13
+ } from '@wordpress/block-editor';
10
14
 
11
15
  export default function separatorSave( { attributes } ) {
12
- const { color, customColor } = attributes;
13
-
16
+ const { backgroundColor, style, opacity } = attributes;
17
+ const customColor = style?.color?.background;
18
+ const colorProps = getColorClassesAndStyles( attributes );
14
19
  // The hr support changing color using border-color, since border-color
15
20
  // is not yet supported in the color palette, we use background-color.
16
- const backgroundClass = getColorClassName( 'background-color', color );
21
+
17
22
  // The dots styles uses text for the dots, to change those dots color is
18
23
  // using color, not backgroundColor.
19
- const colorClass = getColorClassName( 'color', color );
24
+ const colorClass = getColorClassName( 'color', backgroundColor );
20
25
 
21
- const className = classnames( {
22
- 'has-text-color has-background': color || customColor,
23
- [ backgroundClass ]: backgroundClass,
24
- [ colorClass ]: colorClass,
25
- } );
26
+ const className = classnames(
27
+ {
28
+ 'has-text-color': backgroundColor || customColor,
29
+ [ colorClass ]: colorClass,
30
+ 'has-css-opacity': opacity === 'css',
31
+ 'has-alpha-channel-opacity': opacity === 'alpha-channel',
32
+ },
33
+ colorProps.className
34
+ );
26
35
 
27
- const style = {
28
- backgroundColor: backgroundClass ? undefined : customColor,
36
+ const styles = {
37
+ backgroundColor: colorProps?.style?.backgroundColor,
29
38
  color: colorClass ? undefined : customColor,
30
39
  };
31
-
32
- return <hr { ...useBlockProps.save( { className, style } ) } />;
40
+ return <hr { ...useBlockProps.save( { className, style: styles } ) } />;
33
41
  }
@@ -0,0 +1,113 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { render } from '@testing-library/react';
5
+
6
+ /**
7
+ * WordPress dependencies
8
+ */
9
+ import { useBlockProps } from '@wordpress/block-editor';
10
+
11
+ /**
12
+ * Internal dependencies
13
+ */
14
+ import SeparatorEdit from '../edit';
15
+
16
+ jest.mock( '@wordpress/block-editor', () => ( {
17
+ ...jest.requireActual( '@wordpress/block-editor' ),
18
+ useBlockProps: jest.fn(),
19
+ } ) );
20
+
21
+ const defaultAttributes = {
22
+ backgroundColor: undefined,
23
+ opacity: 'alpha-channel',
24
+ style: {},
25
+ className: '',
26
+ };
27
+ const defaultProps = {
28
+ attributes: defaultAttributes,
29
+ setAttributes: jest.fn(),
30
+ };
31
+
32
+ describe( 'Separator block edit method', () => {
33
+ beforeEach( () => {
34
+ useBlockProps.mockClear();
35
+ } );
36
+
37
+ test( 'should add the has-alpha-channel-opacity class and no inline styles by default', () => {
38
+ render( <SeparatorEdit { ...defaultProps } /> );
39
+ expect( useBlockProps ).toHaveBeenCalledWith( {
40
+ className: 'has-alpha-channel-opacity',
41
+ style: undefined,
42
+ } );
43
+ } );
44
+
45
+ test( 'should add has-css-opacity class and no inline styles for deprecated block with no color specified', () => {
46
+ const props = {
47
+ ...defaultProps,
48
+ attributes: { ...defaultAttributes, opacity: 'css' },
49
+ };
50
+ render( <SeparatorEdit { ...props } /> );
51
+ expect( useBlockProps ).toHaveBeenCalledWith( {
52
+ className: 'has-css-opacity',
53
+ style: undefined,
54
+ } );
55
+ } );
56
+
57
+ test( 'should add inline background style for block without dots style selected and custom color specified', () => {
58
+ const props = {
59
+ ...defaultProps,
60
+ attributes: {
61
+ ...defaultAttributes,
62
+ style: { color: { background: '#ff0000' } },
63
+ },
64
+ };
65
+ render( <SeparatorEdit { ...props } /> );
66
+ expect( useBlockProps ).toHaveBeenCalledWith( {
67
+ // For backwards compatibility the has-text-color class is also added even though it is only needed for
68
+ // is-style-dots as this class was always added to v1 blocks, so may be expected by themes and plugins.
69
+ className: 'has-text-color has-alpha-channel-opacity',
70
+ style: {
71
+ backgroundColor: '#ff0000',
72
+ color: '#ff0000',
73
+ },
74
+ } );
75
+ } );
76
+
77
+ test( 'should add inline color style for block with dots style selected and custom color specified', () => {
78
+ const props = {
79
+ ...defaultProps,
80
+ attributes: {
81
+ ...defaultAttributes,
82
+ className: 'is-style-dots',
83
+ style: { color: { background: '#ff0000' } },
84
+ },
85
+ };
86
+ render( <SeparatorEdit { ...props } /> );
87
+ expect( useBlockProps ).toHaveBeenCalledWith( {
88
+ className: 'has-text-color has-alpha-channel-opacity',
89
+ style: {
90
+ backgroundColor: '#ff0000',
91
+ color: '#ff0000',
92
+ },
93
+ } );
94
+ } );
95
+
96
+ test( 'should add color class when color from palette specified', () => {
97
+ const props = {
98
+ ...defaultProps,
99
+ attributes: {
100
+ ...defaultAttributes,
101
+ backgroundColor: 'banana',
102
+ },
103
+ };
104
+ render( <SeparatorEdit { ...props } /> );
105
+ // Note that only the manual addition of the text color class can be checked as the
106
+ // background color classes are added by useBlockProps which has to be mocked.
107
+ expect( useBlockProps ).toHaveBeenCalledWith( {
108
+ className:
109
+ 'has-text-color has-banana-color has-alpha-channel-opacity',
110
+ style: undefined,
111
+ } );
112
+ } );
113
+ } );
@@ -1,9 +1,15 @@
1
+ // Import styles for rendering the static content of deprecated block versions.
2
+ @import "./deprecated.scss";
3
+
1
4
  .wp-block-separator {
2
5
  border: none;
3
6
  border-bottom: 2px solid currentColor;
4
7
  margin-left: auto;
5
8
  margin-right: auto;
6
- opacity: 0.4;
9
+
10
+ &.has-alpha-channel-opacity {
11
+ opacity: initial;
12
+ }
7
13
 
8
14
  // Default, thin style
9
15
  &:not(.is-style-wide):not(.is-style-dots) {
@@ -0,0 +1,41 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useEffect, useState } from '@wordpress/element';
5
+ import { usePrevious } from '@wordpress/compose';
6
+
7
+ export default function useDeprecatedOpacity(
8
+ opacity,
9
+ currentColor,
10
+ setAttributes
11
+ ) {
12
+ const [
13
+ deprecatedOpacityWithNoColor,
14
+ setDeprecatedOpacityWithNoColor,
15
+ ] = useState( false );
16
+ const previousColor = usePrevious( currentColor );
17
+
18
+ // A separator with no color set will always have previousColor set to undefined,
19
+ // and we need to differentiate these from those with color set that will return
20
+ // previousColor as undefined on the first render.
21
+ useEffect( () => {
22
+ if ( opacity === 'css' && ! currentColor && ! previousColor ) {
23
+ setDeprecatedOpacityWithNoColor( true );
24
+ }
25
+ }, [ currentColor, previousColor, opacity ] );
26
+
27
+ // For deprecated blocks, that have a default 0.4 css opacity set, we
28
+ // need to remove this if the current color is changed, or a color is added.
29
+ // In these instances the opacity attribute is set back to the default of
30
+ // alpha-channel which allows a new custom opacity to be set via the color picker.
31
+ useEffect( () => {
32
+ if (
33
+ opacity === 'css' &&
34
+ ( ( deprecatedOpacityWithNoColor && currentColor ) ||
35
+ ( previousColor && currentColor !== previousColor ) )
36
+ ) {
37
+ setAttributes( { opacity: 'alpha-channel' } );
38
+ setDeprecatedOpacityWithNoColor( false );
39
+ }
40
+ }, [ deprecatedOpacityWithNoColor, currentColor, previousColor ] );
41
+ }
@@ -1,4 +1,5 @@
1
- .wp-block[data-align="center"] > .wp-block-site-logo {
1
+ .wp-block[data-align="center"] > .wp-block-site-logo,
2
+ .wp-block-site-logo.aligncenter > div {
2
3
  display: table;
3
4
  margin-left: auto;
4
5
  margin-right: auto;
@@ -45,6 +46,7 @@
45
46
 
46
47
  // Style the placeholder.
47
48
  .components-placeholder {
49
+ display: flex;
48
50
  justify-content: center;
49
51
  align-items: center;
50
52
  box-shadow: none;
@@ -56,7 +56,7 @@
56
56
  }
57
57
  },
58
58
  "spacing": {
59
- "blockGap": true,
59
+ "blockGap": [ "horizontal", "vertical" ],
60
60
  "margin": [ "top", "bottom" ],
61
61
  "units": [ "px", "em", "rem", "vh", "vw" ],
62
62
  "__experimentalDefaultControls": {