@wordpress/block-library 7.8.0 → 7.9.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 (292) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/audio/edit.js +1 -0
  3. package/build/audio/edit.js.map +1 -1
  4. package/build/audio/save.js +2 -1
  5. package/build/audio/save.js.map +1 -1
  6. package/build/avatar/hooks.js +2 -2
  7. package/build/avatar/hooks.js.map +1 -1
  8. package/build/button/edit.js +1 -1
  9. package/build/button/edit.js.map +1 -1
  10. package/build/button/index.js +1 -24
  11. package/build/button/index.js.map +1 -1
  12. package/build/button/save.js +1 -1
  13. package/build/button/save.js.map +1 -1
  14. package/build/columns/variations.js +2 -2
  15. package/build/columns/variations.js.map +1 -1
  16. package/build/comment-author-name/edit.js +3 -5
  17. package/build/comment-author-name/edit.js.map +1 -1
  18. package/build/comment-author-name/index.js +0 -4
  19. package/build/comment-author-name/index.js.map +1 -1
  20. package/build/comment-date/edit.js +4 -4
  21. package/build/comment-date/edit.js.map +1 -1
  22. package/build/comment-date/index.js +0 -4
  23. package/build/comment-date/index.js.map +1 -1
  24. package/build/comment-edit-link/index.js +0 -4
  25. package/build/comment-edit-link/index.js.map +1 -1
  26. package/build/comment-reply-link/index.js +0 -4
  27. package/build/comment-reply-link/index.js.map +1 -1
  28. package/build/comments/edit.js +10 -2
  29. package/build/comments/edit.js.map +1 -1
  30. package/build/comments-title/deprecated.js +0 -3
  31. package/build/comments-title/deprecated.js.map +1 -1
  32. package/build/cover/index.js +1 -0
  33. package/build/cover/index.js.map +1 -1
  34. package/build/embed/embed-preview.js +1 -0
  35. package/build/embed/embed-preview.js.map +1 -1
  36. package/build/embed/icons.js +21 -1
  37. package/build/embed/icons.js.map +1 -1
  38. package/build/embed/save.js +1 -0
  39. package/build/embed/save.js.map +1 -1
  40. package/build/embed/variations.js +11 -0
  41. package/build/embed/variations.js.map +1 -1
  42. package/build/file/edit.js +1 -1
  43. package/build/file/edit.js.map +1 -1
  44. package/build/file/save.js +1 -1
  45. package/build/file/save.js.map +1 -1
  46. package/build/gallery/gallery.js +1 -1
  47. package/build/gallery/gallery.js.map +1 -1
  48. package/build/gallery/save.js +1 -1
  49. package/build/gallery/save.js.map +1 -1
  50. package/build/gallery/transforms.js +2 -2
  51. package/build/gallery/transforms.js.map +1 -1
  52. package/build/gallery/v1/edit.js +3 -3
  53. package/build/gallery/v1/edit.js.map +1 -1
  54. package/build/gallery/v1/gallery-image.js +1 -0
  55. package/build/gallery/v1/gallery-image.js.map +1 -1
  56. package/build/gallery/v1/gallery.js +1 -1
  57. package/build/gallery/v1/gallery.js.map +1 -1
  58. package/build/gallery/v1/save.js +10 -2
  59. package/build/gallery/v1/save.js.map +1 -1
  60. package/build/group/index.js +1 -0
  61. package/build/group/index.js.map +1 -1
  62. package/build/html/edit.js +11 -20
  63. package/build/html/edit.js.map +1 -1
  64. package/build/html/preview.js +48 -0
  65. package/build/html/preview.js.map +1 -0
  66. package/build/image/edit.native.js +2 -1
  67. package/build/image/edit.native.js.map +1 -1
  68. package/build/image/image.js +1 -0
  69. package/build/image/image.js.map +1 -1
  70. package/build/image/save.js +1 -0
  71. package/build/image/save.js.map +1 -1
  72. package/build/list/v2/transforms.js +33 -17
  73. package/build/list/v2/transforms.js.map +1 -1
  74. package/build/list-item/hooks/use-enter.js +7 -4
  75. package/build/list-item/hooks/use-enter.js.map +1 -1
  76. package/build/list-item/hooks/use-outdent-list-item.js +36 -15
  77. package/build/list-item/hooks/use-outdent-list-item.js.map +1 -1
  78. package/build/navigation/edit/index.js +1 -1
  79. package/build/navigation/edit/index.js.map +1 -1
  80. package/build/navigation/index.js +9 -0
  81. package/build/navigation/index.js.map +1 -1
  82. package/build/navigation/use-navigation-menu.js +16 -74
  83. package/build/navigation/use-navigation-menu.js.map +1 -1
  84. package/build/navigation/view.js +5 -3
  85. package/build/navigation/view.js.map +1 -1
  86. package/build/navigation-submenu/view.js +5 -3
  87. package/build/navigation-submenu/view.js.map +1 -1
  88. package/build/post-comments-form/edit.js +12 -2
  89. package/build/post-comments-form/edit.js.map +1 -1
  90. package/build/post-comments-form/form.js +1 -1
  91. package/build/post-comments-form/form.js.map +1 -1
  92. package/build/search/edit.js +1 -1
  93. package/build/search/edit.js.map +1 -1
  94. package/build/table/edit.js +1 -0
  95. package/build/table/edit.js.map +1 -1
  96. package/build/table/save.js +2 -1
  97. package/build/table/save.js.map +1 -1
  98. package/build/video/edit.js +1 -0
  99. package/build/video/edit.js.map +1 -1
  100. package/build/video/save.js +1 -0
  101. package/build/video/save.js.map +1 -1
  102. package/build-module/audio/edit.js +2 -1
  103. package/build-module/audio/edit.js.map +1 -1
  104. package/build-module/audio/save.js +3 -2
  105. package/build-module/audio/save.js.map +1 -1
  106. package/build-module/avatar/hooks.js +2 -2
  107. package/build-module/avatar/hooks.js.map +1 -1
  108. package/build-module/button/edit.js +2 -2
  109. package/build-module/button/edit.js.map +1 -1
  110. package/build-module/button/index.js +1 -24
  111. package/build-module/button/index.js.map +1 -1
  112. package/build-module/button/save.js +2 -2
  113. package/build-module/button/save.js.map +1 -1
  114. package/build-module/columns/variations.js +2 -2
  115. package/build-module/columns/variations.js.map +1 -1
  116. package/build-module/comment-author-name/edit.js +3 -5
  117. package/build-module/comment-author-name/edit.js.map +1 -1
  118. package/build-module/comment-author-name/index.js +0 -4
  119. package/build-module/comment-author-name/index.js.map +1 -1
  120. package/build-module/comment-date/edit.js +4 -4
  121. package/build-module/comment-date/edit.js.map +1 -1
  122. package/build-module/comment-date/index.js +0 -4
  123. package/build-module/comment-date/index.js.map +1 -1
  124. package/build-module/comment-edit-link/index.js +0 -4
  125. package/build-module/comment-edit-link/index.js.map +1 -1
  126. package/build-module/comment-reply-link/index.js +0 -4
  127. package/build-module/comment-reply-link/index.js.map +1 -1
  128. package/build-module/comments/edit.js +10 -2
  129. package/build-module/comments/edit.js.map +1 -1
  130. package/build-module/comments-title/deprecated.js +0 -3
  131. package/build-module/comments-title/deprecated.js.map +1 -1
  132. package/build-module/cover/index.js +1 -0
  133. package/build-module/cover/index.js.map +1 -1
  134. package/build-module/embed/embed-preview.js +2 -1
  135. package/build-module/embed/embed-preview.js.map +1 -1
  136. package/build-module/embed/icons.js +19 -0
  137. package/build-module/embed/icons.js.map +1 -1
  138. package/build-module/embed/save.js +2 -1
  139. package/build-module/embed/save.js.map +1 -1
  140. package/build-module/embed/variations.js +12 -1
  141. package/build-module/embed/variations.js.map +1 -1
  142. package/build-module/file/edit.js +2 -2
  143. package/build-module/file/edit.js.map +1 -1
  144. package/build-module/file/save.js +2 -2
  145. package/build-module/file/save.js.map +1 -1
  146. package/build-module/gallery/gallery.js +2 -2
  147. package/build-module/gallery/gallery.js.map +1 -1
  148. package/build-module/gallery/save.js +2 -2
  149. package/build-module/gallery/save.js.map +1 -1
  150. package/build-module/gallery/transforms.js +3 -3
  151. package/build-module/gallery/transforms.js.map +1 -1
  152. package/build-module/gallery/v1/edit.js +4 -4
  153. package/build-module/gallery/v1/edit.js.map +1 -1
  154. package/build-module/gallery/v1/gallery-image.js +2 -1
  155. package/build-module/gallery/v1/gallery-image.js.map +1 -1
  156. package/build-module/gallery/v1/gallery.js +2 -2
  157. package/build-module/gallery/v1/gallery.js.map +1 -1
  158. package/build-module/gallery/v1/save.js +8 -3
  159. package/build-module/gallery/v1/save.js.map +1 -1
  160. package/build-module/group/index.js +1 -0
  161. package/build-module/group/index.js.map +1 -1
  162. package/build-module/html/edit.js +12 -23
  163. package/build-module/html/edit.js.map +1 -1
  164. package/build-module/html/preview.js +38 -0
  165. package/build-module/html/preview.js.map +1 -0
  166. package/build-module/image/edit.native.js +2 -1
  167. package/build-module/image/edit.native.js.map +1 -1
  168. package/build-module/image/image.js +2 -1
  169. package/build-module/image/image.js.map +1 -1
  170. package/build-module/image/save.js +2 -1
  171. package/build-module/image/save.js.map +1 -1
  172. package/build-module/list/v2/transforms.js +32 -17
  173. package/build-module/list/v2/transforms.js.map +1 -1
  174. package/build-module/list-item/hooks/use-enter.js +7 -4
  175. package/build-module/list-item/hooks/use-enter.js.map +1 -1
  176. package/build-module/list-item/hooks/use-outdent-list-item.js +34 -15
  177. package/build-module/list-item/hooks/use-outdent-list-item.js.map +1 -1
  178. package/build-module/navigation/edit/index.js +1 -1
  179. package/build-module/navigation/edit/index.js.map +1 -1
  180. package/build-module/navigation/index.js +9 -0
  181. package/build-module/navigation/index.js.map +1 -1
  182. package/build-module/navigation/use-navigation-menu.js +17 -75
  183. package/build-module/navigation/use-navigation-menu.js.map +1 -1
  184. package/build-module/navigation/view.js +5 -3
  185. package/build-module/navigation/view.js.map +1 -1
  186. package/build-module/navigation-submenu/view.js +5 -3
  187. package/build-module/navigation-submenu/view.js.map +1 -1
  188. package/build-module/post-comments-form/edit.js +12 -3
  189. package/build-module/post-comments-form/edit.js.map +1 -1
  190. package/build-module/post-comments-form/form.js +2 -2
  191. package/build-module/post-comments-form/form.js.map +1 -1
  192. package/build-module/search/edit.js +2 -2
  193. package/build-module/search/edit.js.map +1 -1
  194. package/build-module/table/edit.js +2 -1
  195. package/build-module/table/edit.js.map +1 -1
  196. package/build-module/table/save.js +3 -2
  197. package/build-module/table/save.js.map +1 -1
  198. package/build-module/video/edit.js +2 -1
  199. package/build-module/video/edit.js.map +1 -1
  200. package/build-module/video/save.js +2 -1
  201. package/build-module/video/save.js.map +1 -1
  202. package/build-style/button/style-rtl.css +5 -0
  203. package/build-style/button/style.css +5 -0
  204. package/build-style/editor-rtl.css +3 -0
  205. package/build-style/editor.css +3 -0
  206. package/build-style/file/style-rtl.css +5 -8
  207. package/build-style/file/style.css +5 -8
  208. package/build-style/navigation/style-rtl.css +9 -1
  209. package/build-style/navigation/style.css +9 -1
  210. package/build-style/post-comments/style-rtl.css +2 -1
  211. package/build-style/post-comments/style.css +2 -1
  212. package/build-style/post-comments-form/editor-rtl.css +3 -0
  213. package/build-style/post-comments-form/editor.css +3 -0
  214. package/build-style/post-template/style-rtl.css +9 -18
  215. package/build-style/post-template/style.css +9 -18
  216. package/build-style/search/style-rtl.css +6 -8
  217. package/build-style/search/style.css +6 -8
  218. package/build-style/style-rtl.css +36 -36
  219. package/build-style/style.css +36 -36
  220. package/package.json +28 -28
  221. package/src/audio/edit.js +4 -0
  222. package/src/audio/save.js +12 -2
  223. package/src/avatar/hooks.js +6 -9
  224. package/src/button/block.json +1 -24
  225. package/src/button/edit.js +2 -2
  226. package/src/button/save.js +2 -2
  227. package/src/button/style.scss +10 -0
  228. package/src/columns/variations.js +2 -2
  229. package/src/comment-author-name/block.json +0 -4
  230. package/src/comment-author-name/edit.js +3 -12
  231. package/src/comment-date/block.json +0 -4
  232. package/src/comment-date/edit.js +10 -14
  233. package/src/comment-date/index.php +0 -3
  234. package/src/comment-edit-link/block.json +0 -4
  235. package/src/comment-reply-link/block.json +0 -4
  236. package/src/comments/edit.js +24 -4
  237. package/src/comments-title/deprecated.js +0 -2
  238. package/src/cover/block.json +1 -0
  239. package/src/cover/index.php +21 -8
  240. package/src/embed/embed-preview.js +8 -1
  241. package/src/embed/icons.js +25 -0
  242. package/src/embed/save.js +10 -2
  243. package/src/embed/test/__snapshots__/index.native.js.snap +1 -1
  244. package/src/embed/variations.js +10 -0
  245. package/src/file/edit.js +4 -2
  246. package/src/file/save.js +2 -2
  247. package/src/file/style.scss +5 -5
  248. package/src/freeform/editor.scss +0 -2
  249. package/src/gallery/gallery.js +9 -2
  250. package/src/gallery/index.php +4 -0
  251. package/src/gallery/save.js +5 -1
  252. package/src/gallery/test/__snapshots__/index.native.js.snap +2 -2
  253. package/src/gallery/test/helpers.native.js +11 -198
  254. package/src/gallery/test/index.native.js +19 -29
  255. package/src/gallery/transforms.js +3 -3
  256. package/src/gallery/v1/edit.js +3 -4
  257. package/src/gallery/v1/gallery-image.js +4 -0
  258. package/src/gallery/v1/gallery.js +8 -2
  259. package/src/gallery/v1/save.js +20 -3
  260. package/src/group/block.json +1 -0
  261. package/src/html/edit.js +10 -40
  262. package/src/html/preview.js +46 -0
  263. package/src/image/edit.native.js +1 -0
  264. package/src/image/image.js +2 -0
  265. package/src/image/save.js +10 -2
  266. package/src/image/test/edit.native.js +51 -19
  267. package/src/list/v2/transforms.js +22 -7
  268. package/src/list-item/hooks/use-enter.js +9 -6
  269. package/src/list-item/hooks/use-outdent-list-item.js +48 -21
  270. package/src/navigation/block.json +9 -0
  271. package/src/navigation/edit/index.js +1 -0
  272. package/src/navigation/style.scss +10 -1
  273. package/src/navigation/test/use-navigation-menu.js +16 -11
  274. package/src/navigation/use-navigation-menu.js +26 -83
  275. package/src/navigation/view.js +7 -2
  276. package/src/navigation-submenu/view.js +7 -2
  277. package/src/post-comments/index.php +1 -1
  278. package/src/post-comments/style.scss +7 -3
  279. package/src/post-comments-form/edit.js +20 -3
  280. package/src/post-comments-form/editor.scss +4 -0
  281. package/src/post-comments-form/form.js +2 -2
  282. package/src/post-comments-form/index.php +1 -1
  283. package/src/post-featured-image/index.php +4 -2
  284. package/src/post-template/index.php +15 -3
  285. package/src/post-template/style.scss +1 -7
  286. package/src/search/edit.js +2 -2
  287. package/src/search/index.php +12 -10
  288. package/src/search/style.scss +9 -8
  289. package/src/table/edit.js +2 -0
  290. package/src/table/save.js +6 -1
  291. package/src/video/edit.js +4 -0
  292. package/src/video/save.js +10 -2
@@ -13,7 +13,11 @@ import classnames from 'classnames/dedupe';
13
13
  */
14
14
  import { __, sprintf } from '@wordpress/i18n';
15
15
  import { Placeholder, SandBox } from '@wordpress/components';
16
- import { RichText, BlockIcon } from '@wordpress/block-editor';
16
+ import {
17
+ RichText,
18
+ BlockIcon,
19
+ __experimentalGetElementClassName,
20
+ } from '@wordpress/block-editor';
17
21
  import { Component } from '@wordpress/element';
18
22
  import { createBlock, getDefaultBlockName } from '@wordpress/blocks';
19
23
 
@@ -140,6 +144,9 @@ class EmbedPreview extends Component {
140
144
  { ( ! RichText.isEmpty( caption ) || isSelected ) && (
141
145
  <RichText
142
146
  tagName="figcaption"
147
+ className={ __experimentalGetElementClassName(
148
+ 'caption'
149
+ ) }
143
150
  placeholder={ __( 'Add caption' ) }
144
151
  value={ caption }
145
152
  onChange={ onCaptionChange }
@@ -153,3 +153,28 @@ export const embedWolframIcon = (
153
153
  <Path d="M32.59521,22.001l4.31885-4.84473-6.34131-1.38379.646-6.459-5.94336,2.61035L22,6.31934l-3.27344,5.60351L12.78418,9.3125l.645,6.458L7.08643,17.15234,11.40479,21.999,7.08594,26.84375l6.34131,1.38379-.64551,6.458,5.94287-2.60938L22,37.68066l3.27344-5.60351,5.94287,2.61035-.64551-6.458,6.34277-1.38183Zm.44385,2.75244L30.772,23.97827l-1.59558-2.07391,1.97888.735Zm-8.82147,6.1579L22.75,33.424V30.88977l1.52228-2.22168ZM18.56226,13.48816,19.819,15.09534l-2.49219-.88642L15.94037,12.337Zm6.87719.00116,2.62043-1.15027-1.38654,1.86981L24.183,15.0946Zm3.59357,2.6029-1.22546,1.7381.07525-2.73486,1.44507-1.94867ZM22,29.33008l-2.16406-3.15686L22,23.23688l2.16406,2.93634Zm-4.25458-9.582-.10528-3.836,3.60986,1.284v3.73242Zm5.00458-2.552,3.60986-1.284-.10528,3.836L22.75,20.92853Zm-7.78174-1.10559-.29352-2.94263,1.44245,1.94739.07519,2.73321Zm2.30982,5.08319,3.50817,1.18164-2.16247,2.9342-3.678-1.08447Zm2.4486,7.49285L21.25,30.88977v2.53485L19.78052,30.91Zm3.48707-6.31121,3.50817-1.18164,2.33228,3.03137-3.678,1.08447Zm10.87219-4.28113-2.714,3.04529L28.16418,19.928l1.92176-2.72565ZM24.06036,12.81769l-2.06012,2.6322-2.059-2.63318L22,9.292ZM9.91455,18.07227l4.00079-.87195,1.921,2.72735-3.20794,1.19019Zm2.93024,4.565,1.9801-.73462L13.228,23.97827l-2.26838.77429Zm-1.55591,3.58819L13.701,25.4021l2.64935.78058-2.14447.67853Zm3.64868,1.977L18.19,27.17334l.08313,3.46332L14.52979,32.2793Zm10.7876,2.43549.08447-3.464,3.25165,1.03052.407,4.07684Zm4.06824-3.77478-2.14545-.68,2.65063-.781,2.41266.825Z" />
154
154
  </SVG>
155
155
  );
156
+
157
+ export const embedPocketCastsIcon = {
158
+ foreground: '#f43e37',
159
+ src: (
160
+ <SVG
161
+ width="24"
162
+ height="24"
163
+ viewBox="0 0 24 24"
164
+ fill="none"
165
+ xmlns="http://www.w3.org/2000/svg"
166
+ >
167
+ <Path
168
+ fillRule="evenodd"
169
+ clipRule="evenodd"
170
+ d="M24,12A12,12,0,1,1,12,0,12,12,0,0,1,24,12Z"
171
+ />
172
+ <Path
173
+ fillRule="evenodd"
174
+ clipRule="evenodd"
175
+ d="M2.67,12a9.33,9.33,0,0,1,18.66,0H19a7,7,0,1,0-7,7v2.33A9.33,9.33,0,0,1,2.67,12ZM12,17.6A5.6,5.6,0,1,1,17.6,12h-2A3.56,3.56,0,1,0,12,15.56Z"
176
+ fill="#fff"
177
+ />
178
+ </SVG>
179
+ ),
180
+ };
package/src/embed/save.js CHANGED
@@ -6,7 +6,11 @@ import classnames from 'classnames/dedupe';
6
6
  /**
7
7
  * WordPress dependencies
8
8
  */
9
- import { RichText, useBlockProps } from '@wordpress/block-editor';
9
+ import {
10
+ RichText,
11
+ useBlockProps,
12
+ __experimentalGetElementClassName,
13
+ } from '@wordpress/block-editor';
10
14
 
11
15
  export default function save( { attributes } ) {
12
16
  const { url, caption, type, providerNameSlug } = attributes;
@@ -27,7 +31,11 @@ export default function save( { attributes } ) {
27
31
  { `\n${ url }\n` /* URL needs to be on its own line. */ }
28
32
  </div>
29
33
  { ! RichText.isEmpty( caption ) && (
30
- <RichText.Content tagName="figcaption" value={ caption } />
34
+ <RichText.Content
35
+ className={ __experimentalGetElementClassName( 'caption' ) }
36
+ tagName="figcaption"
37
+ value={ caption }
38
+ />
31
39
  ) }
32
40
  </figure>
33
41
  );
@@ -186,6 +186,6 @@ exports[`Embed block sets block caption 1`] = `
186
186
  "<!-- wp:embed {\\"url\\":\\"https://twitter.com/notnownikki\\",\\"type\\":\\"rich\\",\\"providerNameSlug\\":\\"twitter\\",\\"responsive\\":true} -->
187
187
  <figure class=\\"wp-block-embed is-type-rich is-provider-twitter wp-block-embed-twitter\\"><div class=\\"wp-block-embed__wrapper\\">
188
188
  https://twitter.com/notnownikki
189
- </div><figcaption>Caption</figcaption></figure>
189
+ </div><figcaption class=\\"wp-element-caption\\">Caption</figcaption></figure>
190
190
  <!-- /wp:embed -->"
191
191
  `;
@@ -26,6 +26,7 @@ import {
26
26
  embedDailymotionIcon,
27
27
  embedPinterestIcon,
28
28
  embedWolframIcon,
29
+ embedPocketCastsIcon,
29
30
  } from './icons';
30
31
 
31
32
  /** @typedef {import('@wordpress/blocks').WPBlockVariation} WPBlockVariation */
@@ -216,6 +217,15 @@ const variations = [
216
217
  patterns: [ /^https?:\/\/(www\.)?mixcloud\.com\/.+/i ],
217
218
  attributes: { providerNameSlug: 'mixcloud', responsive: true },
218
219
  },
220
+ {
221
+ name: 'pocketcasts',
222
+ title: 'Pocket Casts',
223
+ icon: embedPocketCastsIcon,
224
+ keywords: [ __( 'podcast' ), __( 'audio' ) ],
225
+ description: __( 'Embed a podcast player from Pocket Casts.' ),
226
+ patterns: [ /^https:\/\/pca.st\/\w+/i ],
227
+ attributes: { providerNameSlug: 'pocketcasts', responsive: true },
228
+ },
219
229
  {
220
230
  name: 'reddit',
221
231
  title: 'Reddit',
package/src/file/edit.js CHANGED
@@ -22,7 +22,7 @@ import {
22
22
  RichText,
23
23
  useBlockProps,
24
24
  store as blockEditorStore,
25
- __experimentalElementButtonClassName,
25
+ __experimentalGetElementClassName,
26
26
  } from '@wordpress/block-editor';
27
27
  import { useEffect } from '@wordpress/element';
28
28
  import { useCopyToClipboard } from '@wordpress/compose';
@@ -302,7 +302,9 @@ function FileEdit( {
302
302
  aria-label={ __( 'Download button text' ) }
303
303
  className={ classnames(
304
304
  'wp-block-file__button',
305
- __experimentalElementButtonClassName
305
+ __experimentalGetElementClassName(
306
+ 'button'
307
+ )
306
308
  ) }
307
309
  value={ downloadButtonText }
308
310
  withoutInteractiveFormatting
package/src/file/save.js CHANGED
@@ -9,7 +9,7 @@ import classnames from 'classnames';
9
9
  import {
10
10
  RichText,
11
11
  useBlockProps,
12
- __experimentalElementButtonClassName,
12
+ __experimentalGetElementClassName,
13
13
  } from '@wordpress/block-editor';
14
14
  import { __, sprintf } from '@wordpress/i18n';
15
15
 
@@ -74,7 +74,7 @@ export default function save( { attributes } ) {
74
74
  href={ href }
75
75
  className={ classnames(
76
76
  'wp-block-file__button',
77
- __experimentalElementButtonClassName
77
+ __experimentalGetElementClassName( 'button' )
78
78
  ) }
79
79
  download={ true }
80
80
  aria-describedby={ describedById }
@@ -1,6 +1,10 @@
1
1
  .wp-block-file {
2
2
  margin-bottom: 1.5em;
3
3
 
4
+ &:not(.wp-element-button) {
5
+ font-size: 0.8em;
6
+ }
7
+
4
8
  &.aligncenter {
5
9
  text-align: center;
6
10
  }
@@ -20,15 +24,11 @@
20
24
  }
21
25
 
22
26
  //This needs a low specificity so it won't override the rules from the button element if defined in theme.json.
23
- .wp-block-file__button {
24
- background: #32373c;
27
+ :where(.wp-block-file__button) {
25
28
  border-radius: 2em;
26
- color: $white;
27
- font-size: 0.8em;
28
29
  padding: 0.5em 1em;
29
30
 
30
31
  &:is(a) {
31
- text-decoration: none;
32
32
 
33
33
  &:hover,
34
34
  &:visited,
@@ -211,8 +211,6 @@
211
211
  margin: 0;
212
212
  text-align: center;
213
213
  padding: 6px;
214
- -webkit-box-sizing: border-box;
215
- -moz-box-sizing: border-box;
216
214
  box-sizing: border-box;
217
215
  }
218
216
 
@@ -6,7 +6,11 @@ import classnames from 'classnames';
6
6
  /**
7
7
  * WordPress dependencies
8
8
  */
9
- import { RichText, useInnerBlocksProps } from '@wordpress/block-editor';
9
+ import {
10
+ RichText,
11
+ useInnerBlocksProps,
12
+ __experimentalGetElementClassName,
13
+ } from '@wordpress/block-editor';
10
14
  import { VisuallyHidden } from '@wordpress/components';
11
15
  import { useState, useEffect } from '@wordpress/element';
12
16
  import { __ } from '@wordpress/i18n';
@@ -82,7 +86,10 @@ export const Gallery = ( props ) => {
82
86
  captionFocused={ captionFocused }
83
87
  onFocusCaption={ onFocusCaption }
84
88
  tagName="figcaption"
85
- className="blocks-gallery-caption"
89
+ className={ classnames(
90
+ 'blocks-gallery-caption',
91
+ __experimentalGetElementClassName( 'caption' )
92
+ ) }
86
93
  aria-label={ __( 'Gallery caption text' ) }
87
94
  placeholder={ __( 'Write gallery caption…' ) }
88
95
  value={ caption }
@@ -50,9 +50,13 @@ function block_core_gallery_render( $attributes, $content ) {
50
50
  // because we only want to match against the value, not the CSS attribute.
51
51
  if ( is_array( $gap ) ) {
52
52
  foreach ( $gap as $key => $value ) {
53
+ // Make sure $value is a string to avoid PHP 8.1 deprecation error in preg_match() when the value is null.
54
+ $value = is_string( $value ) ? $value : '';
53
55
  $gap[ $key ] = $value && preg_match( '%[\\\(&=}]|/\*%', $value ) ? null : $value;
54
56
  }
55
57
  } else {
58
+ // Make sure $gap is a string to avoid PHP 8.1 deprecation error in preg_match() when the value is null.
59
+ $gap = is_string( $gap ) ? $gap : '';
56
60
  $gap = $gap && preg_match( '%[\\\(&=}]|/\*%', $gap ) ? null : $gap;
57
61
  }
58
62
 
@@ -10,6 +10,7 @@ import {
10
10
  RichText,
11
11
  useBlockProps,
12
12
  useInnerBlocksProps,
13
+ __experimentalGetElementClassName,
13
14
  } from '@wordpress/block-editor';
14
15
 
15
16
  /**
@@ -39,7 +40,10 @@ export default function saveWithInnerBlocks( { attributes } ) {
39
40
  { ! RichText.isEmpty( caption ) && (
40
41
  <RichText.Content
41
42
  tagName="figcaption"
42
- className="blocks-gallery-caption"
43
+ className={ classnames(
44
+ 'blocks-gallery-caption',
45
+ __experimentalGetElementClassName( 'caption' )
46
+ ) }
43
47
  value={ caption }
44
48
  />
45
49
  ) }
@@ -114,14 +114,14 @@ exports[`Gallery block sets caption to gallery 1`] = `
114
114
  "<!-- wp:gallery {\\"linkTo\\":\\"none\\"} -->
115
115
  <figure class=\\"wp-block-gallery has-nested-images columns-default is-cropped\\"><!-- wp:image {\\"id\\":2000} -->
116
116
  <figure class=\\"wp-block-image\\"><img src=\\"https://test-site.files.wordpress.com/local-image-1.jpeg\\" alt=\\"\\" class=\\"wp-image-2000\\"/></figure>
117
- <!-- /wp:image --><figcaption class=\\"blocks-gallery-caption\\"><strong>Bold</strong> <em>italic</em> <s>strikethrough</s> gallery caption</figcaption></figure>
117
+ <!-- /wp:image --><figcaption class=\\"blocks-gallery-caption wp-element-caption\\"><strong>Bold</strong> <em>italic</em> <s>strikethrough</s> gallery caption</figcaption></figure>
118
118
  <!-- /wp:gallery -->"
119
119
  `;
120
120
 
121
121
  exports[`Gallery block sets caption to gallery items 1`] = `
122
122
  "<!-- wp:gallery {\\"linkTo\\":\\"none\\"} -->
123
123
  <figure class=\\"wp-block-gallery has-nested-images columns-default is-cropped\\"><!-- wp:image {\\"id\\":2000} -->
124
- <figure class=\\"wp-block-image\\"><img src=\\"https://test-site.files.wordpress.com/local-image-1.jpeg\\" alt=\\"\\" class=\\"wp-image-2000\\"/><figcaption><strong>Bold</strong> <em>italic</em> <s>strikethrough</s> image caption</figcaption></figure>
124
+ <figure class=\\"wp-block-image\\"><img src=\\"https://test-site.files.wordpress.com/local-image-1.jpeg\\" alt=\\"\\" class=\\"wp-image-2000\\"/><figcaption class=\\"wp-element-caption\\"><strong>Bold</strong> <em>italic</em> <s>strikethrough</s> image caption</figcaption></figure>
125
125
  <!-- /wp:image --></figure>
126
126
  <!-- /wp:gallery -->"
127
127
  `;
@@ -2,28 +2,14 @@
2
2
  * External dependencies
3
3
  */
4
4
  import {
5
- act,
6
- initializeEditor,
5
+ addBlock,
7
6
  fireEvent,
8
- waitFor,
9
- within,
10
- waitForStoreResolvers,
7
+ getBlock,
8
+ getInnerBlock,
9
+ initializeEditor,
10
+ triggerBlockListLayout,
11
11
  } from 'test/helpers';
12
12
 
13
- /**
14
- * WordPress dependencies
15
- */
16
- import {
17
- requestMediaPicker,
18
- subscribeMediaUpload,
19
- } from '@wordpress/react-native-bridge';
20
- import {
21
- MEDIA_UPLOAD_STATE_UPLOADING,
22
- MEDIA_UPLOAD_STATE_SUCCEEDED,
23
- MEDIA_UPLOAD_STATE_FAILED,
24
- MEDIA_UPLOAD_STATE_RESET,
25
- } from '@wordpress/block-editor';
26
-
27
13
  /**
28
14
  * Adds a Gallery block via the block picker.
29
15
  *
@@ -31,54 +17,10 @@ import {
31
17
  */
32
18
  export const addGalleryBlock = async () => {
33
19
  const screen = await initializeEditor();
34
- const { getByA11yLabel, getByTestId, getByText } = screen;
35
-
36
- fireEvent.press( getByA11yLabel( 'Add block' ) );
37
-
38
- const blockList = getByTestId( 'InserterUI-Blocks' );
39
- // onScroll event used to force the FlatList to render all items
40
- fireEvent.scroll( blockList, {
41
- nativeEvent: {
42
- contentOffset: { y: 0, x: 0 },
43
- contentSize: { width: 100, height: 100 },
44
- layoutMeasurement: { width: 100, height: 100 },
45
- },
46
- } );
47
-
48
- fireEvent.press( await waitFor( () => getByText( 'Gallery' ) ) );
49
-
20
+ await addBlock( screen, 'Gallery' );
50
21
  return screen;
51
22
  };
52
23
 
53
- /**
54
- * The gallery items are rendered via the FlatList of the inner block list.
55
- * In order to render the items of a FlatList, it's required to trigger the
56
- * "onLayout" event. Additionally, the call is wrapped over "waitForStoreResolvers"
57
- * because the gallery items request the media data associated with the image to
58
- * be rendered via the "getMedia" selector.
59
- *
60
- * @param {import('react-test-renderer').ReactTestInstance} galleryBlock Gallery block instance to trigger layout event.
61
- * @param {Object} [options] Configuration options for the event.
62
- * @param {number} [options.width] Width value to be passed to the event.
63
- */
64
- export const triggerGalleryLayout = async (
65
- galleryBlock,
66
- { width = 320 } = {}
67
- ) =>
68
- waitForStoreResolvers( () =>
69
- fireEvent(
70
- within( galleryBlock ).getByTestId( 'block-list-wrapper' ),
71
- 'layout',
72
- {
73
- nativeEvent: {
74
- layout: {
75
- width,
76
- },
77
- },
78
- }
79
- )
80
- );
81
-
82
24
  /**
83
25
  * Initialize the editor with HTML generated of Gallery block.
84
26
  *
@@ -106,12 +48,11 @@ export const initializeWithGalleryBlock = async ( {
106
48
  useLocalUrl,
107
49
  } );
108
50
  const screen = await initializeEditor( { initialHtml } );
109
- const { getByA11yLabel } = screen;
110
51
 
111
- const galleryBlock = getByA11yLabel( /Gallery Block\. Row 1/ );
52
+ const galleryBlock = getBlock( screen, 'Gallery' );
112
53
 
113
54
  if ( numberOfItems > 0 ) {
114
- await triggerGalleryLayout( galleryBlock, { width } );
55
+ await triggerBlockListLayout( galleryBlock, { width } );
115
56
  }
116
57
 
117
58
  if ( selected ) {
@@ -125,109 +66,11 @@ export const initializeWithGalleryBlock = async ( {
125
66
  * Gets a gallery item within a Gallery block.
126
67
  *
127
68
  * @param {import('react-test-renderer').ReactTestInstance} galleryBlock Gallery block instance.
128
- * @param {number} rowPosition Row position within the Gallery block.
69
+ * @param {number} rowIndex Row position within the Gallery block.
129
70
  * @return {import('react-test-renderer').ReactTestInstance} Gallery item.
130
71
  */
131
- export const getGalleryItem = ( galleryBlock, rowPosition ) => {
132
- return within( galleryBlock ).getByA11yLabel(
133
- new RegExp( `Image Block\\. Row ${ rowPosition }` )
134
- );
135
- };
136
-
137
- /**
138
- * Sets up the media upload mock functions for testing.
139
- *
140
- * @typedef {Object} MediaUploadMockFunctions
141
- * @property {Function} notifyUploadingState Notify uploading state for a media item.
142
- * @property {Function} notifySucceedState Notify succeed state for a media item.
143
- * @property {Function} notifyFailedState Notify failed state for a media item.
144
- * @property {Function} notifyResetState Notify reset state for a media item.
145
- *
146
- * @return {MediaUploadMockFunctions} Notify state functions.
147
- */
148
- export const setupMediaUpload = () => {
149
- const mediaUploadListeners = [];
150
- subscribeMediaUpload.mockImplementation( ( callback ) => {
151
- mediaUploadListeners.push( callback );
152
- return { remove: jest.fn() };
153
- } );
154
- const notifyMediaUpload = ( payload ) =>
155
- mediaUploadListeners.forEach( ( listener ) => listener( payload ) );
156
-
157
- return {
158
- notifyUploadingState: async ( mediaItem ) =>
159
- act( async () => {
160
- notifyMediaUpload( {
161
- state: MEDIA_UPLOAD_STATE_UPLOADING,
162
- mediaId: mediaItem.localId,
163
- progress: 0.25,
164
- } );
165
- } ),
166
- notifySucceedState: async ( mediaItem ) =>
167
- act( async () => {
168
- notifyMediaUpload( {
169
- state: MEDIA_UPLOAD_STATE_SUCCEEDED,
170
- mediaId: mediaItem.localId,
171
- mediaUrl: mediaItem.serverUrl,
172
- mediaServerId: mediaItem.serverId,
173
- } );
174
- } ),
175
- notifyFailedState: async ( mediaItem ) =>
176
- act( async () => {
177
- notifyMediaUpload( {
178
- state: MEDIA_UPLOAD_STATE_FAILED,
179
- mediaId: mediaItem.localId,
180
- progress: 0.5,
181
- } );
182
- } ),
183
- notifyResetState: async ( mediaItem ) =>
184
- act( async () => {
185
- notifyMediaUpload( {
186
- state: MEDIA_UPLOAD_STATE_RESET,
187
- mediaId: mediaItem.localId,
188
- progress: 0,
189
- } );
190
- } ),
191
- };
192
- };
193
-
194
- /**
195
- *
196
- * Sets up Media Picker mock functions.
197
- *
198
- * @typedef {Object} MediaPickerMockFunctions
199
- * @property {Function} expectMediaPickerCall Checks if the request media picker function has been called with specific arguments.
200
- * @property {Function} mediaPickerCallback Callback function to notify the media items picked from the media picker.
201
- *
202
- * @return {MediaPickerMockFunctions} Media picker mock functions.
203
- */
204
- export const setupMediaPicker = () => {
205
- let mediaPickerCallback;
206
- requestMediaPicker.mockImplementation(
207
- ( source, filter, multiple, callback ) => {
208
- mediaPickerCallback = callback;
209
- }
210
- );
211
- return {
212
- expectMediaPickerCall: ( source, filter, multiple ) =>
213
- expect( requestMediaPicker ).toHaveBeenCalledWith(
214
- source,
215
- filter,
216
- multiple,
217
- mediaPickerCallback
218
- ),
219
- mediaPickerCallback: async ( ...mediaItems ) =>
220
- act( async () =>
221
- mediaPickerCallback(
222
- mediaItems.map( ( { localId, localUrl } ) => ( {
223
- type: 'image',
224
- url: localUrl,
225
- id: localId,
226
- } ) )
227
- )
228
- ),
229
- };
230
- };
72
+ export const getGalleryItem = ( galleryBlock, rowIndex ) =>
73
+ getInnerBlock( galleryBlock, 'Image', { rowIndex } );
231
74
 
232
75
  /**
233
76
  * Generates the HTML of a Gallery block.
@@ -261,33 +104,3 @@ export const generateGalleryBlock = (
261
104
  <figure class="wp-block-gallery has-nested-images columns-default is-cropped">${ galleryItems }</figure>
262
105
  <!-- /wp:gallery -->`;
263
106
  };
264
-
265
- /**
266
- * Sets the text of a caption.
267
- *
268
- * @param {import('react-test-renderer').ReactTestInstance} element Caption test instance.
269
- * @param {string} text Text to be set.
270
- */
271
- export const setCaption = ( element, text ) => {
272
- fireEvent( element, 'focus' );
273
- fireEvent( element, 'onChange', {
274
- nativeEvent: {
275
- eventCount: 1,
276
- target: undefined,
277
- text,
278
- },
279
- } );
280
- };
281
-
282
- /**
283
- * Opens the block settings of the current selected block.
284
- *
285
- * @param {import('@testing-library/react-native').RenderAPI} screen The Testing Library screen.
286
- */
287
- export const openBlockSettings = async ( screen ) => {
288
- const { getByA11yLabel, getByTestId } = screen;
289
- fireEvent.press( getByA11yLabel( 'Open Settings' ) );
290
- await waitFor(
291
- () => getByTestId( 'block-settings-modal' ).props.isVisible
292
- );
293
- };
@@ -3,17 +3,22 @@
3
3
  */
4
4
  import {
5
5
  act,
6
+ changeTextOfRichText,
7
+ fireEvent,
8
+ getBlock,
6
9
  getEditorHtml,
7
10
  initializeEditor,
8
- fireEvent,
11
+ openBlockSettings,
12
+ setupCoreBlocks,
13
+ setupMediaPicker,
14
+ setupMediaUpload,
15
+ triggerBlockListLayout,
9
16
  within,
10
17
  } from 'test/helpers';
11
18
 
12
19
  /**
13
20
  * WordPress dependencies
14
21
  */
15
- import { getBlockTypes, unregisterBlockType } from '@wordpress/blocks';
16
- import { registerCoreBlocks } from '@wordpress/block-library';
17
22
  import { Platform } from '@wordpress/element';
18
23
  import {
19
24
  getOtherMediaOptions,
@@ -28,12 +33,7 @@ import {
28
33
  addGalleryBlock,
29
34
  initializeWithGalleryBlock,
30
35
  getGalleryItem,
31
- setupMediaUpload,
32
36
  generateGalleryBlock,
33
- setCaption,
34
- setupMediaPicker,
35
- triggerGalleryLayout,
36
- openBlockSettings,
37
37
  } from './helpers';
38
38
 
39
39
  const media = [
@@ -57,23 +57,13 @@ const media = [
57
57
  },
58
58
  ];
59
59
 
60
- beforeAll( () => {
61
- // Register all core blocks
62
- registerCoreBlocks();
63
- } );
64
-
65
- afterAll( () => {
66
- // Clean up registered blocks
67
- getBlockTypes().forEach( ( block ) => {
68
- unregisterBlockType( block.name );
69
- } );
70
- } );
60
+ setupCoreBlocks();
71
61
 
72
62
  describe( 'Gallery block', () => {
73
63
  it( 'inserts block', async () => {
74
- const { getByA11yLabel } = await addGalleryBlock();
64
+ const screen = await addGalleryBlock();
75
65
 
76
- expect( getByA11yLabel( /Gallery Block\. Row 1/ ) ).toBeVisible();
66
+ expect( getBlock( screen, 'Gallery' ) ).toBeVisible();
77
67
  expect( getEditorHtml() ).toMatchSnapshot();
78
68
  } );
79
69
 
@@ -183,7 +173,7 @@ describe( 'Gallery block', () => {
183
173
  const captionField = within(
184
174
  getByA11yLabel( /Gallery caption. Empty/ )
185
175
  ).getByPlaceholderText( 'Add caption' );
186
- setCaption(
176
+ changeTextOfRichText(
187
177
  captionField,
188
178
  '<strong>Bold</strong> <em>italic</em> <s>strikethrough</s> gallery caption'
189
179
  );
@@ -207,7 +197,7 @@ describe( 'Gallery block', () => {
207
197
  // Set gallery item caption
208
198
  const captionField =
209
199
  within( galleryItem ).getByPlaceholderText( 'Add caption' );
210
- setCaption(
200
+ changeTextOfRichText(
211
201
  captionField,
212
202
  '<strong>Bold</strong> <em>italic</em> <s>strikethrough</s> image caption'
213
203
  );
@@ -234,7 +224,7 @@ describe( 'Gallery block', () => {
234
224
  await mediaPickerCallback( media[ 0 ], media[ 1 ] );
235
225
 
236
226
  // Check that gallery items are visible
237
- await triggerGalleryLayout( galleryBlock );
227
+ await triggerBlockListLayout( galleryBlock );
238
228
  const galleryItem1 = getGalleryItem( galleryBlock, 1 );
239
229
  const galleryItem2 = getGalleryItem( galleryBlock, 2 );
240
230
  expect( galleryItem1 ).toBeVisible();
@@ -272,7 +262,7 @@ describe( 'Gallery block', () => {
272
262
  await mediaPickerCallback( media[ 0 ], media[ 1 ] );
273
263
 
274
264
  // Check that gallery items are visible
275
- await triggerGalleryLayout( galleryBlock );
265
+ await triggerBlockListLayout( galleryBlock );
276
266
  const galleryItem1 = getGalleryItem( galleryBlock, 1 );
277
267
  const galleryItem2 = getGalleryItem( galleryBlock, 2 );
278
268
  expect( galleryItem1 ).toBeVisible();
@@ -326,7 +316,7 @@ describe( 'Gallery block', () => {
326
316
  await mediaPickerCallback( media[ 0 ] );
327
317
 
328
318
  // Check gallery item is visible
329
- await triggerGalleryLayout( galleryBlock );
319
+ await triggerBlockListLayout( galleryBlock );
330
320
  const galleryItem = getGalleryItem( galleryBlock, 1 );
331
321
  expect( galleryItem ).toBeVisible();
332
322
 
@@ -382,7 +372,7 @@ describe( 'Gallery block', () => {
382
372
  );
383
373
 
384
374
  // Check that gallery items are visible
385
- await triggerGalleryLayout( galleryBlock );
375
+ await triggerBlockListLayout( galleryBlock );
386
376
  const galleryItem1 = getGalleryItem( galleryBlock, 1 );
387
377
  const galleryItem2 = getGalleryItem( galleryBlock, 2 );
388
378
  expect( galleryItem1 ).toBeVisible();
@@ -420,7 +410,7 @@ describe( 'Gallery block', () => {
420
410
  await mediaPickerCallback( media[ 0 ], media[ 1 ] );
421
411
 
422
412
  // Check that gallery items are visible
423
- await triggerGalleryLayout( galleryBlock );
413
+ await triggerBlockListLayout( galleryBlock );
424
414
  const galleryItem1 = getGalleryItem( galleryBlock, 1 );
425
415
  const galleryItem2 = getGalleryItem( galleryBlock, 2 );
426
416
  expect( galleryItem1 ).toBeVisible();
@@ -519,7 +509,7 @@ describe( 'Gallery block', () => {
519
509
  await mediaPickerCallback( otherAppsMedia[ 0 ], otherAppsMedia[ 1 ] );
520
510
 
521
511
  // Check that gallery items are visible
522
- await triggerGalleryLayout( galleryBlock );
512
+ await triggerBlockListLayout( galleryBlock );
523
513
  const galleryItem1 = getGalleryItem( galleryBlock, 1 );
524
514
  const galleryItem2 = getGalleryItem( galleryBlock, 2 );
525
515
  expect( galleryItem1 ).toBeVisible();
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { filter, every, toString } from 'lodash';
4
+ import { filter, every } from 'lodash';
5
5
 
6
6
  /**
7
7
  * WordPress dependencies
@@ -160,7 +160,7 @@ const transforms = {
160
160
  return createBlock( 'core/gallery', {
161
161
  images: validImages.map(
162
162
  ( { id, url, alt, caption } ) => ( {
163
- id: toString( id ),
163
+ id: id.toString(),
164
164
  url,
165
165
  alt,
166
166
  caption,
@@ -182,7 +182,7 @@ const transforms = {
182
182
  shortcode: ( { named: { ids } } ) => {
183
183
  if ( ! isGalleryV2Enabled() ) {
184
184
  return parseShortcodeIds( ids ).map( ( id ) => ( {
185
- id: toString( id ),
185
+ id: id.toString(),
186
186
  } ) );
187
187
  }
188
188
  },