@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
@@ -20,7 +20,7 @@ import { store as coreStore } from '@wordpress/core-data';
20
20
  import { useCommentQueryArgs, useCommentTree } from './hooks';
21
21
 
22
22
  const TEMPLATE = [
23
- [ 'core/comment-author-avatar' ],
23
+ [ 'core/avatar' ],
24
24
  [ 'core/comment-author-name' ],
25
25
  [ 'core/comment-date' ],
26
26
  [ 'core/comment-content' ],
@@ -31,6 +31,10 @@ const TEMPLATE = [
31
31
  /**
32
32
  * Function that returns a comment structure that will be rendered with default placehoders.
33
33
  *
34
+ * Each comment has a `commentId` property that is always a negative number in
35
+ * case of the placeholders. This is to ensure that the comment does not
36
+ * conflict with the actual (real) comments.
37
+ *
34
38
  * @param {Object} settings Discussion Settings.
35
39
  * @param {number} [settings.perPage] - Comments per page setting or block attribute.
36
40
  * @param {boolean} [settings.threadComments] - Enable threaded (nested) comments setting.
@@ -54,12 +58,13 @@ const getCommentsPlaceholder = ( {
54
58
  perPage <= commentsDepth ? perPage : commentsDepth;
55
59
  if ( ! threadComments || defaultCommentsToShow === 1 ) {
56
60
  // If displaying threaded comments is disabled, we only show one comment
57
- return [ { commentId: null, children: [] } ];
61
+ // A commentId is negative in order to avoid conflicts with the actual comments.
62
+ return [ { commentId: -1, children: [] } ];
58
63
  } else if ( defaultCommentsToShow === 2 ) {
59
64
  return [
60
65
  {
61
- commentId: null,
62
- children: [ { commentId: null, children: [] } ],
66
+ commentId: -1,
67
+ children: [ { commentId: -2, children: [] } ],
63
68
  },
64
69
  ];
65
70
  }
@@ -67,11 +72,11 @@ const getCommentsPlaceholder = ( {
67
72
  // In case that the value is set but larger than 3 we truncate it to 3.
68
73
  return [
69
74
  {
70
- commentId: null,
75
+ commentId: -1,
71
76
  children: [
72
77
  {
73
- commentId: null,
74
- children: [ { commentId: null, children: [] } ],
78
+ commentId: -2,
79
+ children: [ { commentId: -3, children: [] } ],
75
80
  },
76
81
  ],
77
82
  },
@@ -81,29 +86,32 @@ const getCommentsPlaceholder = ( {
81
86
  /**
82
87
  * Component which renders the inner blocks of the Comment Template.
83
88
  *
84
- * @param {Object} props Component props.
85
- * @param {Array} [props.comment] - A comment object.
86
- * @param {Array} [props.activeComment] - The block that is currently active.
87
- * @param {Array} [props.setActiveComment] - The setter for activeComment.
88
- * @param {Array} [props.firstComment] - First comment in the array.
89
- * @param {Array} [props.blocks] - Array of blocks returned from
90
- * getBlocks() in parent .
89
+ * @param {Object} props Component props.
90
+ * @param {Array} [props.comment] - A comment object.
91
+ * @param {Array} [props.activeCommentId] - The ID of the comment that is currently active.
92
+ * @param {Array} [props.setActiveCommentId] - The setter for activeCommentId.
93
+ * @param {Array} [props.firstCommentId] - ID of the first comment in the array.
94
+ * @param {Array} [props.blocks] - Array of blocks returned from
95
+ * getBlocks() in parent .
91
96
  * @return {WPElement} Inner blocks of the Comment Template
92
97
  */
93
98
  function CommentTemplateInnerBlocks( {
94
99
  comment,
95
- activeComment,
96
- setActiveComment,
97
- firstComment,
100
+ activeCommentId,
101
+ setActiveCommentId,
102
+ firstCommentId,
98
103
  blocks,
99
104
  } ) {
100
105
  const { children, ...innerBlocksProps } = useInnerBlocksProps(
101
106
  {},
102
107
  { template: TEMPLATE }
103
108
  );
109
+
104
110
  return (
105
111
  <li { ...innerBlocksProps }>
106
- { comment === ( activeComment || firstComment ) ? children : null }
112
+ { comment.commentId === ( activeCommentId || firstCommentId )
113
+ ? children
114
+ : null }
107
115
 
108
116
  { /* To avoid flicker when switching active block contexts, a preview
109
117
  is ALWAYS rendered and the preview for the active block is hidden.
@@ -114,17 +122,20 @@ function CommentTemplateInnerBlocks( {
114
122
  block. */ }
115
123
  <MemoizedCommentTemplatePreview
116
124
  blocks={ blocks }
117
- comment={ comment }
118
- setActiveComment={ setActiveComment }
119
- isHidden={ comment === ( activeComment || firstComment ) }
125
+ commentId={ comment.commentId }
126
+ setActiveCommentId={ setActiveCommentId }
127
+ isHidden={
128
+ comment.commentId === ( activeCommentId || firstCommentId )
129
+ }
120
130
  />
121
131
 
122
132
  { comment?.children?.length > 0 ? (
123
133
  <CommentsList
124
134
  comments={ comment.children }
125
- activeComment={ activeComment }
126
- setActiveComment={ setActiveComment }
135
+ activeCommentId={ activeCommentId }
136
+ setActiveCommentId={ setActiveCommentId }
127
137
  blocks={ blocks }
138
+ firstCommentId={ firstCommentId }
128
139
  />
129
140
  ) : null }
130
141
  </li>
@@ -133,8 +144,8 @@ function CommentTemplateInnerBlocks( {
133
144
 
134
145
  const CommentTemplatePreview = ( {
135
146
  blocks,
136
- comment,
137
- setActiveComment,
147
+ commentId,
148
+ setActiveCommentId,
138
149
  isHidden,
139
150
  } ) => {
140
151
  const blockPreviewProps = useBlockPreview( {
@@ -142,7 +153,7 @@ const CommentTemplatePreview = ( {
142
153
  } );
143
154
 
144
155
  const handleOnClick = () => {
145
- setActiveComment( comment );
156
+ setActiveCommentId( commentId );
146
157
  };
147
158
 
148
159
  // We have to hide the preview block if the `comment` props points to
@@ -172,35 +183,44 @@ const MemoizedCommentTemplatePreview = memo( CommentTemplatePreview );
172
183
  /**
173
184
  * Component that renders a list of (nested) comments. It is called recursively.
174
185
  *
175
- * @param {Object} props Component props.
176
- * @param {Array} [props.comments] - Array of comment objects.
177
- * @param {Array} [props.blockProps] - Props from parent's `useBlockProps()`.
178
- * @param {Array} [props.activeComment] - The block that is currently active.
179
- * @param {Array} [props.setActiveComment] - The setter for activeComment.
180
- * @param {Array} [props.blocks] - Array of blocks returned from
181
- * getBlocks() in parent .
186
+ * @param {Object} props Component props.
187
+ * @param {Array} [props.comments] - Array of comment objects.
188
+ * @param {Array} [props.blockProps] - Props from parent's `useBlockProps()`.
189
+ * @param {Array} [props.activeCommentId] - The ID of the comment that is currently active.
190
+ * @param {Array} [props.setActiveCommentId] - The setter for activeCommentId.
191
+ * @param {Array} [props.blocks] - Array of blocks returned from getBlocks() in parent.
192
+ * @param {Object} [props.firstCommentId] - The ID of the first comment in the array of
193
+ * comment objects.
182
194
  * @return {WPElement} List of comments.
183
195
  */
184
196
  const CommentsList = ( {
185
197
  comments,
186
198
  blockProps,
187
- activeComment,
188
- setActiveComment,
199
+ activeCommentId,
200
+ setActiveCommentId,
189
201
  blocks,
202
+ firstCommentId,
190
203
  } ) => (
191
204
  <ol { ...blockProps }>
192
205
  { comments &&
193
- comments.map( ( comment, index ) => (
206
+ comments.map( ( { commentId, ...comment }, index ) => (
194
207
  <BlockContextProvider
195
208
  key={ comment.commentId || index }
196
- value={ comment }
209
+ value={ {
210
+ // If the commentId is negative it means that this comment is a
211
+ // "placeholder" and that the block is most likely being used in the
212
+ // site editor. In this case, we have to set the commentId to `null`
213
+ // because otherwise the (non-existent) comment with a negative ID
214
+ // would be reqested from the REST API.
215
+ commentId: commentId < 0 ? null : commentId,
216
+ } }
197
217
  >
198
218
  <CommentTemplateInnerBlocks
199
- comment={ comment }
200
- activeComment={ activeComment }
201
- setActiveComment={ setActiveComment }
219
+ comment={ { commentId, ...comment } }
220
+ activeCommentId={ activeCommentId }
221
+ setActiveCommentId={ setActiveCommentId }
202
222
  blocks={ blocks }
203
- firstComment={ comments[ 0 ] }
223
+ firstCommentId={ firstCommentId }
204
224
  />
205
225
  </BlockContextProvider>
206
226
  ) ) }
@@ -219,7 +239,7 @@ export default function CommentTemplateEdit( {
219
239
  } ) {
220
240
  const blockProps = useBlockProps();
221
241
 
222
- const [ activeComment, setActiveComment ] = useState();
242
+ const [ activeCommentId, setActiveCommentId ] = useState();
223
243
  const { commentOrder, threadCommentsDepth, threadComments } = useSelect(
224
244
  ( select ) => {
225
245
  const { getSettings } = select( blockEditorStore );
@@ -285,8 +305,9 @@ export default function CommentTemplateEdit( {
285
305
  comments={ commentTree }
286
306
  blockProps={ blockProps }
287
307
  blocks={ blocks }
288
- activeComment={ activeComment }
289
- setActiveComment={ setActiveComment }
308
+ activeCommentId={ activeCommentId }
309
+ setActiveCommentId={ setActiveCommentId }
310
+ firstCommentId={ commentTree[ 0 ]?.commentId }
290
311
  />
291
312
  );
292
313
  }
package/src/cover/edit.js CHANGED
@@ -9,7 +9,13 @@ import namesPlugin from 'colord/plugins/names';
9
9
  /**
10
10
  * WordPress dependencies
11
11
  */
12
- import { Fragment, useEffect, useRef, useState } from '@wordpress/element';
12
+ import {
13
+ Fragment,
14
+ useEffect,
15
+ useRef,
16
+ useState,
17
+ useMemo,
18
+ } from '@wordpress/element';
13
19
  import {
14
20
  BaseControl,
15
21
  Button,
@@ -22,10 +28,11 @@ import {
22
28
  Spinner,
23
29
  TextareaControl,
24
30
  ToggleControl,
25
- withNotices,
26
31
  __experimentalUseCustomUnits as useCustomUnits,
27
32
  __experimentalBoxControl as BoxControl,
28
33
  __experimentalToolsPanelItem as ToolsPanelItem,
34
+ __experimentalUnitControl as UnitControl,
35
+ __experimentalParseQuantityAndUnitFromRawValue as parseQuantityAndUnitFromRawValue,
29
36
  } from '@wordpress/components';
30
37
  import { compose, useInstanceId } from '@wordpress/compose';
31
38
  import {
@@ -41,7 +48,6 @@ import {
41
48
  useInnerBlocksProps,
42
49
  __experimentalUseGradient,
43
50
  __experimentalPanelColorGradientSettings as PanelColorGradientSettings,
44
- __experimentalUnitControl as UnitControl,
45
51
  __experimentalBlockAlignmentMatrixControl as BlockAlignmentMatrixControl,
46
52
  __experimentalBlockFullHeightAligmentControl as FullHeightAlignmentControl,
47
53
  store as blockEditorStore,
@@ -50,6 +56,7 @@ import { __ } from '@wordpress/i18n';
50
56
  import { useSelect, useDispatch } from '@wordpress/data';
51
57
  import { cover as icon } from '@wordpress/icons';
52
58
  import { isBlobURL } from '@wordpress/blob';
59
+ import { store as noticesStore } from '@wordpress/notices';
53
60
 
54
61
  /**
55
62
  * Internal dependencies
@@ -96,8 +103,6 @@ function CoverHeightInput( {
96
103
  unit = 'px',
97
104
  value = '',
98
105
  } ) {
99
- const [ temporaryInput, setTemporaryInput ] = useState( null );
100
-
101
106
  const instanceId = useInstanceId( UnitControl );
102
107
  const inputId = `block-cover-height-input-${ instanceId }`;
103
108
  const isPx = unit === 'px';
@@ -120,20 +125,16 @@ function CoverHeightInput( {
120
125
  : undefined;
121
126
 
122
127
  if ( isNaN( inputValue ) && inputValue !== undefined ) {
123
- setTemporaryInput( unprocessedValue );
124
128
  return;
125
129
  }
126
- setTemporaryInput( null );
127
130
  onChange( inputValue );
128
131
  };
129
132
 
130
- const handleOnBlur = () => {
131
- if ( temporaryInput !== null ) {
132
- setTemporaryInput( null );
133
- }
134
- };
133
+ const computedValue = useMemo( () => {
134
+ const [ parsedQuantity ] = parseQuantityAndUnitFromRawValue( value );
135
+ return [ parsedQuantity, unit ].join( '' );
136
+ }, [ unit, value ] );
135
137
 
136
- const inputValue = temporaryInput !== null ? temporaryInput : value;
137
138
  const min = isPx ? COVER_MIN_HEIGHT : 0;
138
139
 
139
140
  return (
@@ -142,13 +143,11 @@ function CoverHeightInput( {
142
143
  id={ inputId }
143
144
  isResetValueOnUnitChange
144
145
  min={ min }
145
- onBlur={ handleOnBlur }
146
146
  onChange={ handleOnChange }
147
147
  onUnitChange={ onUnitChange }
148
148
  style={ { maxWidth: 80 } }
149
- unit={ unit }
150
149
  units={ units }
151
- value={ inputValue }
150
+ value={ computedValue }
152
151
  />
153
152
  </BaseControl>
154
153
  );
@@ -266,12 +265,10 @@ const isTemporaryMedia = ( id, url ) => ! id && isBlobURL( url );
266
265
  function CoverPlaceholder( {
267
266
  disableMediaButtons = false,
268
267
  children,
269
- noticeUI,
270
- noticeOperations,
271
268
  onSelectMedia,
269
+ onError,
272
270
  style,
273
271
  } ) {
274
- const { removeAllNotices, createErrorNotice } = noticeOperations;
275
272
  return (
276
273
  <MediaPlaceholder
277
274
  icon={ <BlockIcon icon={ icon } /> }
@@ -284,12 +281,8 @@ function CoverPlaceholder( {
284
281
  onSelect={ onSelectMedia }
285
282
  accept="image/*,video/*"
286
283
  allowedTypes={ ALLOWED_MEDIA_TYPES }
287
- notices={ noticeUI }
288
284
  disableMediaButtons={ disableMediaButtons }
289
- onError={ ( message ) => {
290
- removeAllNotices();
291
- createErrorNotice( message );
292
- } }
285
+ onError={ onError }
293
286
  style={ style }
294
287
  >
295
288
  { children }
@@ -301,8 +294,6 @@ function CoverEdit( {
301
294
  attributes,
302
295
  clientId,
303
296
  isSelected,
304
- noticeUI,
305
- noticeOperations,
306
297
  overlayColor,
307
298
  setAttributes,
308
299
  setOverlayColor,
@@ -328,6 +319,7 @@ function CoverEdit( {
328
319
  const { __unstableMarkNextChangeAsNotPersistent } = useDispatch(
329
320
  blockEditorStore
330
321
  );
322
+ const { createErrorNotice } = useDispatch( noticesStore );
331
323
  const {
332
324
  gradientClass,
333
325
  gradientValue,
@@ -382,6 +374,12 @@ function CoverEdit( {
382
374
  } );
383
375
  };
384
376
 
377
+ const onUploadError = ( message ) => {
378
+ createErrorNotice( Array.isArray( message ) ? message[ 2 ] : message, {
379
+ type: 'snackbar',
380
+ } );
381
+ };
382
+
385
383
  const isDarkElement = useRef();
386
384
  const isCoverDark = useCoverIsDark(
387
385
  url,
@@ -640,9 +638,8 @@ function CoverEdit( {
640
638
  ) }
641
639
  >
642
640
  <CoverPlaceholder
643
- noticeUI={ noticeUI }
644
641
  onSelectMedia={ onSelectMedia }
645
- noticeOperations={ noticeOperations }
642
+ onError={ onUploadError }
646
643
  style={ {
647
644
  minHeight: minHeightWithUnit || undefined,
648
645
  } }
@@ -763,9 +760,8 @@ function CoverEdit( {
763
760
  { isUploadingMedia && <Spinner /> }
764
761
  <CoverPlaceholder
765
762
  disableMediaButtons
766
- noticeUI={ noticeUI }
767
763
  onSelectMedia={ onSelectMedia }
768
- noticeOperations={ noticeOperations }
764
+ onError={ onUploadError }
769
765
  />
770
766
  <div { ...innerBlocksProps } />
771
767
  </div>
@@ -775,5 +771,4 @@ function CoverEdit( {
775
771
 
776
772
  export default compose( [
777
773
  withColors( { overlayColor: 'background-color' } ),
778
- withNotices,
779
774
  ] )( CoverEdit );
package/src/editor.scss CHANGED
@@ -1,5 +1,6 @@
1
1
  @import "./archives/editor.scss";
2
2
  @import "./audio/editor.scss";
3
+ @import "./avatar/editor.scss";
3
4
  @import "./block/editor.scss";
4
5
  @import "./button/editor.scss";
5
6
  @import "./buttons/editor.scss";
@@ -344,9 +344,9 @@ const variations = [
344
344
  },
345
345
  {
346
346
  name: 'wolfram-cloud',
347
- title: 'Wolfram Cloud',
347
+ title: 'Wolfram',
348
348
  icon: embedWolframIcon,
349
- description: __( 'Embed Wolfram Cloud notebook content.' ),
349
+ description: __( 'Embed Wolfram notebook content.' ),
350
350
  patterns: [ /^https?:\/\/(www\.)?wolframcloud\.com\/obj\/.+/i ],
351
351
  attributes: { providerNameSlug: 'wolfram-cloud', responsive: true },
352
352
  },
@@ -106,7 +106,23 @@
106
106
  },
107
107
  "supports": {
108
108
  "anchor": true,
109
- "align": true
109
+ "align": true,
110
+ "html": false,
111
+ "units": [ "px", "em", "rem", "vh", "vw" ],
112
+ "spacing": {
113
+ "blockGap": true,
114
+ "__experimentalDefaultControls": {
115
+ "blockGap": true
116
+ }
117
+ },
118
+ "__experimentalLayout": {
119
+ "allowSwitching": false,
120
+ "allowInheriting": false,
121
+ "allowEditing": false,
122
+ "default": {
123
+ "type": "flex"
124
+ }
125
+ }
110
126
  },
111
127
  "editorStyle": "wp-block-gallery-editor",
112
128
  "style": "wp-block-gallery"
@@ -1,7 +1,7 @@
1
1
  // Deprecated gallery styles pre refactoring to use nested image blocks.
2
2
  // https://github.com/WordPress/gutenberg/pull/25940.
3
- .wp-block-gallery,
4
- .blocks-gallery-grid {
3
+ .wp-block-gallery:not(.has-nested-images),
4
+ .blocks-gallery-grid:not(.has-nested-images) {
5
5
  display: flex;
6
6
  flex-wrap: wrap;
7
7
  list-style-type: none;
@@ -54,6 +54,7 @@ import useImageSizes from './use-image-sizes';
54
54
  import useShortCodeTransform from './use-short-code-transform';
55
55
  import useGetNewImages from './use-get-new-images';
56
56
  import useGetMedia from './use-get-media';
57
+ import GapStyles from './gap-styles';
57
58
 
58
59
  const MAX_COLUMNS = 8;
59
60
  const linkOptions = [
@@ -99,7 +100,8 @@ function GalleryEdit( props ) {
99
100
  __unstableMarkNextChangeAsNotPersistent,
100
101
  replaceInnerBlocks,
101
102
  updateBlockAttributes,
102
- multiSelect,
103
+ selectBlock,
104
+ clearSelectedBlock,
103
105
  } = useDispatch( blockEditorStore );
104
106
  const { createSuccessNotice } = useDispatch( noticesStore );
105
107
 
@@ -155,13 +157,8 @@ function GalleryEdit( props ) {
155
157
  align: undefined,
156
158
  } );
157
159
  } );
158
-
159
- // If new blocks added select the first of these so they scroll into view.
160
- if ( newImages?.length ) {
161
- multiSelect(
162
- newImages[ 0 ].clientId,
163
- newImages[ newImages?.length - 1 ].clientId
164
- );
160
+ if ( newImages?.length > 0 ) {
161
+ clearSelectedBlock();
165
162
  }
166
163
  }, [ newImages ] );
167
164
 
@@ -296,6 +293,10 @@ function GalleryEdit( props ) {
296
293
  } );
297
294
  } );
298
295
 
296
+ if ( newBlocks?.length > 0 ) {
297
+ selectBlock( newBlocks[ 0 ].clientId );
298
+ }
299
+
299
300
  replaceInnerBlocks(
300
301
  clientId,
301
302
  concat( existingImageBlocks, newBlocks ).sort(
@@ -548,6 +549,12 @@ function GalleryEdit( props ) {
548
549
  />
549
550
  </BlockControls>
550
551
  { noticeUI }
552
+ { Platform.isWeb && (
553
+ <GapStyles
554
+ blockGap={ attributes.style?.spacing?.blockGap }
555
+ clientId={ clientId }
556
+ />
557
+ ) }
551
558
  <Gallery
552
559
  { ...props }
553
560
  images={ images }
@@ -4,7 +4,6 @@ figure.wp-block-gallery {
4
4
  // See https://github.com/WordPress/gutenberg/pull/10358
5
5
 
6
6
  display: block;
7
- margin: 0;
8
7
  &.has-nested-images {
9
8
  .components-drop-zone {
10
9
  display: none;
@@ -69,13 +69,14 @@ export const Gallery = ( props ) => {
69
69
  ) }
70
70
  >
71
71
  { children }
72
-
73
- <View
74
- className="blocks-gallery-media-placeholder-wrapper"
75
- onClick={ removeCaptionFocus }
76
- >
77
- { mediaPlaceholder }
78
- </View>
72
+ { isSelected && ! children && (
73
+ <View
74
+ className="blocks-gallery-media-placeholder-wrapper"
75
+ onClick={ removeCaptionFocus }
76
+ >
77
+ { mediaPlaceholder }
78
+ </View>
79
+ ) }
79
80
  <RichTextVisibilityHelper
80
81
  isHidden={ ! isSelected && RichText.isEmpty( caption ) }
81
82
  captionFocused={ captionFocused }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { BlockList } from '@wordpress/block-editor';
5
+ import { useContext, createPortal } from '@wordpress/element';
6
+
7
+ export default function GapStyles( { blockGap, clientId } ) {
8
+ const styleElement = useContext( BlockList.__unstableElementContext );
9
+
10
+ const gap = blockGap
11
+ ? `#block-${ clientId } { --wp--style--unstable-gallery-gap: ${ blockGap } }`
12
+ : `#block-${ clientId } { --wp--style--unstable-gallery-gap: var( --wp--style--block-gap, 0.5em ) }`;
13
+
14
+ const GapStyle = () => {
15
+ return <style>{ gap }</style>;
16
+ };
17
+
18
+ return gap && styleElement
19
+ ? createPortal( <GapStyle />, styleElement )
20
+ : null;
21
+ }
@@ -32,12 +32,53 @@ function block_core_gallery_data_id_backcompatibility( $parsed_block ) {
32
32
 
33
33
  add_filter( 'render_block_data', 'block_core_gallery_data_id_backcompatibility' );
34
34
 
35
+ /**
36
+ * Adds a style tag for the --wp--style--unstable-gallery-gap var.
37
+ *
38
+ * The Gallery block needs to recalculate Image block width based on
39
+ * the current gap setting in order to maintain the number of flex columns
40
+ * so a css var is added to allow this.
41
+ *
42
+ * @param array $attributes Attributes of the block being rendered.
43
+ * @param string $content Content of the block being rendered.
44
+ * @return string The content of the block being rendered.
45
+ */
46
+ function block_core_gallery_render( $attributes, $content ) {
47
+ $gap = _wp_array_get( $attributes, array( 'style', 'spacing', 'blockGap' ) );
48
+ // Skip if gap value contains unsupported characters.
49
+ // Regex for CSS value borrowed from `safecss_filter_attr`, and used here
50
+ // because we only want to match against the value, not the CSS attribute.
51
+ $gap = preg_match( '%[\\\(&=}]|/\*%', $gap ) ? null : $gap;
52
+ $id = uniqid();
53
+ $class = 'wp-block-gallery-' . $id;
54
+ $content = preg_replace(
55
+ '/' . preg_quote( 'class="', '/' ) . '/',
56
+ 'class="' . $class . ' ',
57
+ $content,
58
+ 1
59
+ );
60
+ $gap_value = $gap ? $gap : 'var( --wp--style--block-gap, 0.5em )';
61
+ $style = '.' . $class . '{ --wp--style--unstable-gallery-gap: ' . $gap_value . '}';
62
+ // Ideally styles should be loaded in the head, but blocks may be parsed
63
+ // after that, so loading in the footer for now.
64
+ // See https://core.trac.wordpress.org/ticket/53494.
65
+ add_action(
66
+ 'wp_footer',
67
+ function () use ( $style ) {
68
+ echo '<style> ' . $style . '</style>';
69
+ }
70
+ );
71
+ return $content;
72
+ }
35
73
  /**
36
74
  * Registers the `core/gallery` block on server.
37
75
  */
38
76
  function register_block_core_gallery() {
39
77
  register_block_type_from_metadata(
40
- __DIR__ . '/gallery'
78
+ __DIR__ . '/gallery',
79
+ array(
80
+ 'render_callback' => 'block_core_gallery_render',
81
+ )
41
82
  );
42
83
  }
43
84