@wordpress/block-library 9.1.0 → 9.3.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 (387) hide show
  1. package/CHANGELOG.md +21 -17
  2. package/build/audio/edit.js +20 -8
  3. package/build/audio/edit.js.map +1 -1
  4. package/build/audio/index.js +4 -0
  5. package/build/audio/index.js.map +1 -1
  6. package/build/audio/transforms.js +1 -1
  7. package/build/audio/transforms.js.map +1 -1
  8. package/build/block/edit.js +0 -1
  9. package/build/block/edit.js.map +1 -1
  10. package/build/block/index.js +5 -1
  11. package/build/block/index.js.map +1 -1
  12. package/build/button/index.js +1 -0
  13. package/build/button/index.js.map +1 -1
  14. package/build/embed/embed-preview.js +4 -4
  15. package/build/embed/embed-preview.js.map +1 -1
  16. package/build/file/edit.js +14 -6
  17. package/build/file/edit.js.map +1 -1
  18. package/build/file/index.js +4 -0
  19. package/build/file/index.js.map +1 -1
  20. package/build/file/transforms.js +2 -3
  21. package/build/file/transforms.js.map +1 -1
  22. package/build/gallery/deprecated.js +6 -54
  23. package/build/gallery/deprecated.js.map +1 -1
  24. package/build/gallery/edit.js +9 -8
  25. package/build/gallery/edit.js.map +1 -1
  26. package/build/gallery/index.js +2 -2
  27. package/build/gallery/index.js.map +1 -1
  28. package/build/gallery/save.js +0 -11
  29. package/build/gallery/save.js.map +1 -1
  30. package/build/gallery/shared.js +0 -27
  31. package/build/gallery/shared.js.map +1 -1
  32. package/build/gallery/transforms.js +29 -80
  33. package/build/gallery/transforms.js.map +1 -1
  34. package/build/group/index.js +1 -0
  35. package/build/group/index.js.map +1 -1
  36. package/build/group/placeholder.js +5 -0
  37. package/build/group/placeholder.js.map +1 -1
  38. package/build/image/edit.js +13 -21
  39. package/build/image/edit.js.map +1 -1
  40. package/build/image/image.js +33 -19
  41. package/build/image/image.js.map +1 -1
  42. package/build/image/index.js +4 -0
  43. package/build/image/index.js.map +1 -1
  44. package/build/image/transforms.js +1 -1
  45. package/build/image/transforms.js.map +1 -1
  46. package/build/list-item/edit.js +1 -1
  47. package/build/list-item/edit.js.map +1 -1
  48. package/build/list-item/hooks/use-merge.js +8 -1
  49. package/build/list-item/hooks/use-merge.js.map +1 -1
  50. package/build/list-item/index.js +11 -1
  51. package/build/list-item/index.js.map +1 -1
  52. package/build/lock-unlock.js +1 -1
  53. package/build/lock-unlock.js.map +1 -1
  54. package/build/loginout/index.js +3 -0
  55. package/build/loginout/index.js.map +1 -1
  56. package/build/media-text/edit.js +3 -2
  57. package/build/media-text/edit.js.map +1 -1
  58. package/build/navigation-submenu/edit.js +1 -1
  59. package/build/navigation-submenu/edit.js.map +1 -1
  60. package/build/page-list/convert-to-links-modal.js +1 -1
  61. package/build/page-list/convert-to-links-modal.js.map +1 -1
  62. package/build/page-list/edit.js +1 -1
  63. package/build/page-list/edit.js.map +1 -1
  64. package/build/post-content/index.js +3 -0
  65. package/build/post-content/index.js.map +1 -1
  66. package/build/post-date/edit.js +3 -1
  67. package/build/post-date/edit.js.map +1 -1
  68. package/build/post-excerpt/index.js +3 -0
  69. package/build/post-excerpt/index.js.map +1 -1
  70. package/build/post-title/index.js +3 -0
  71. package/build/post-title/index.js.map +1 -1
  72. package/build/query/edit/inspector-controls/index.js +3 -2
  73. package/build/query/edit/inspector-controls/index.js.map +1 -1
  74. package/build/query/edit/query-toolbar.js +54 -61
  75. package/build/query/edit/query-toolbar.js.map +1 -1
  76. package/build/query/index.js +34 -0
  77. package/build/query/index.js.map +1 -1
  78. package/build/quote/edit.js +1 -0
  79. package/build/quote/edit.js.map +1 -1
  80. package/build/site-tagline/index.js +1 -0
  81. package/build/site-tagline/index.js.map +1 -1
  82. package/build/site-title/index.js +1 -0
  83. package/build/site-title/index.js.map +1 -1
  84. package/build/social-link/edit.js +9 -3
  85. package/build/social-link/edit.js.map +1 -1
  86. package/build/table/edit.js +8 -17
  87. package/build/table/edit.js.map +1 -1
  88. package/build/table-of-contents/index.js +1 -1
  89. package/build/template-part/edit/title-modal.js +1 -1
  90. package/build/template-part/edit/title-modal.js.map +1 -1
  91. package/build/utils/caption.js +2 -1
  92. package/build/utils/caption.js.map +1 -1
  93. package/build/utils/hooks.js +12 -0
  94. package/build/utils/hooks.js.map +1 -1
  95. package/build/verse/index.js +1 -0
  96. package/build/verse/index.js.map +1 -1
  97. package/build/video/deprecated.js +4 -0
  98. package/build/video/deprecated.js.map +1 -1
  99. package/build/video/edit.js +17 -7
  100. package/build/video/edit.js.map +1 -1
  101. package/build/video/index.js +4 -0
  102. package/build/video/index.js.map +1 -1
  103. package/build/video/transforms.js +1 -1
  104. package/build/video/transforms.js.map +1 -1
  105. package/build-module/audio/edit.js +20 -8
  106. package/build-module/audio/edit.js.map +1 -1
  107. package/build-module/audio/index.js +4 -0
  108. package/build-module/audio/index.js.map +1 -1
  109. package/build-module/audio/transforms.js +1 -1
  110. package/build-module/audio/transforms.js.map +1 -1
  111. package/build-module/block/edit.js +0 -1
  112. package/build-module/block/edit.js.map +1 -1
  113. package/build-module/block/index.js +5 -1
  114. package/build-module/block/index.js.map +1 -1
  115. package/build-module/button/index.js +1 -0
  116. package/build-module/button/index.js.map +1 -1
  117. package/build-module/embed/embed-preview.js +4 -4
  118. package/build-module/embed/embed-preview.js.map +1 -1
  119. package/build-module/file/edit.js +15 -7
  120. package/build-module/file/edit.js.map +1 -1
  121. package/build-module/file/index.js +4 -0
  122. package/build-module/file/index.js.map +1 -1
  123. package/build-module/file/transforms.js +2 -3
  124. package/build-module/file/transforms.js.map +1 -1
  125. package/build-module/gallery/deprecated.js +6 -54
  126. package/build-module/gallery/deprecated.js.map +1 -1
  127. package/build-module/gallery/edit.js +10 -9
  128. package/build-module/gallery/edit.js.map +1 -1
  129. package/build-module/gallery/index.js +1 -1
  130. package/build-module/gallery/index.js.map +1 -1
  131. package/build-module/gallery/save.js +0 -11
  132. package/build-module/gallery/save.js.map +1 -1
  133. package/build-module/gallery/shared.js +0 -25
  134. package/build-module/gallery/shared.js.map +1 -1
  135. package/build-module/gallery/transforms.js +29 -80
  136. package/build-module/gallery/transforms.js.map +1 -1
  137. package/build-module/group/index.js +1 -0
  138. package/build-module/group/index.js.map +1 -1
  139. package/build-module/group/placeholder.js +5 -0
  140. package/build-module/group/placeholder.js.map +1 -1
  141. package/build-module/image/edit.js +12 -20
  142. package/build-module/image/edit.js.map +1 -1
  143. package/build-module/image/image.js +28 -14
  144. package/build-module/image/image.js.map +1 -1
  145. package/build-module/image/index.js +4 -0
  146. package/build-module/image/index.js.map +1 -1
  147. package/build-module/image/transforms.js +1 -1
  148. package/build-module/image/transforms.js.map +1 -1
  149. package/build-module/list-item/edit.js +1 -1
  150. package/build-module/list-item/edit.js.map +1 -1
  151. package/build-module/list-item/hooks/use-merge.js +8 -1
  152. package/build-module/list-item/hooks/use-merge.js.map +1 -1
  153. package/build-module/list-item/index.js +11 -1
  154. package/build-module/list-item/index.js.map +1 -1
  155. package/build-module/lock-unlock.js +1 -1
  156. package/build-module/lock-unlock.js.map +1 -1
  157. package/build-module/loginout/index.js +3 -0
  158. package/build-module/loginout/index.js.map +1 -1
  159. package/build-module/media-text/edit.js +3 -2
  160. package/build-module/media-text/edit.js.map +1 -1
  161. package/build-module/navigation-submenu/edit.js +1 -1
  162. package/build-module/navigation-submenu/edit.js.map +1 -1
  163. package/build-module/page-list/convert-to-links-modal.js +1 -1
  164. package/build-module/page-list/convert-to-links-modal.js.map +1 -1
  165. package/build-module/page-list/edit.js +1 -1
  166. package/build-module/page-list/edit.js.map +1 -1
  167. package/build-module/post-content/index.js +3 -0
  168. package/build-module/post-content/index.js.map +1 -1
  169. package/build-module/post-date/edit.js +4 -2
  170. package/build-module/post-date/edit.js.map +1 -1
  171. package/build-module/post-excerpt/index.js +3 -0
  172. package/build-module/post-excerpt/index.js.map +1 -1
  173. package/build-module/post-title/index.js +3 -0
  174. package/build-module/post-title/index.js.map +1 -1
  175. package/build-module/query/edit/inspector-controls/index.js +3 -2
  176. package/build-module/query/edit/inspector-controls/index.js.map +1 -1
  177. package/build-module/query/edit/query-toolbar.js +55 -62
  178. package/build-module/query/edit/query-toolbar.js.map +1 -1
  179. package/build-module/query/index.js +34 -0
  180. package/build-module/query/index.js.map +1 -1
  181. package/build-module/quote/edit.js +1 -0
  182. package/build-module/quote/edit.js.map +1 -1
  183. package/build-module/site-tagline/index.js +1 -0
  184. package/build-module/site-tagline/index.js.map +1 -1
  185. package/build-module/site-title/index.js +1 -0
  186. package/build-module/site-title/index.js.map +1 -1
  187. package/build-module/social-link/edit.js +9 -3
  188. package/build-module/social-link/edit.js.map +1 -1
  189. package/build-module/table/edit.js +9 -18
  190. package/build-module/table/edit.js.map +1 -1
  191. package/build-module/table-of-contents/index.js +1 -1
  192. package/build-module/template-part/edit/title-modal.js +1 -1
  193. package/build-module/template-part/edit/title-modal.js.map +1 -1
  194. package/build-module/utils/caption.js +2 -1
  195. package/build-module/utils/caption.js.map +1 -1
  196. package/build-module/utils/hooks.js +11 -0
  197. package/build-module/utils/hooks.js.map +1 -1
  198. package/build-module/verse/index.js +1 -0
  199. package/build-module/verse/index.js.map +1 -1
  200. package/build-module/video/deprecated.js +4 -0
  201. package/build-module/video/deprecated.js.map +1 -1
  202. package/build-module/video/edit.js +18 -8
  203. package/build-module/video/edit.js.map +1 -1
  204. package/build-module/video/index.js +4 -0
  205. package/build-module/video/index.js.map +1 -1
  206. package/build-module/video/transforms.js +1 -1
  207. package/build-module/video/transforms.js.map +1 -1
  208. package/build-style/audio/style-rtl.css +1 -1
  209. package/build-style/audio/style.css +1 -1
  210. package/build-style/audio/theme-rtl.css +2 -2
  211. package/build-style/audio/theme.css +2 -2
  212. package/build-style/common-rtl.css +1 -3
  213. package/build-style/common.css +1 -3
  214. package/build-style/editor-rtl.css +3 -12
  215. package/build-style/editor.css +3 -12
  216. package/build-style/embed/style-rtl.css +1 -1
  217. package/build-style/embed/style.css +1 -1
  218. package/build-style/embed/theme-rtl.css +2 -2
  219. package/build-style/embed/theme.css +2 -2
  220. package/build-style/image/editor-rtl.css +0 -12
  221. package/build-style/image/editor.css +0 -12
  222. package/build-style/image/style-rtl.css +7 -1
  223. package/build-style/image/style.css +7 -1
  224. package/build-style/media-text/style-rtl.css +4 -0
  225. package/build-style/media-text/style.css +4 -0
  226. package/build-style/navigation/style-rtl.css +1 -0
  227. package/build-style/navigation/style.css +1 -0
  228. package/build-style/post-comments-form/style-rtl.css +11 -10
  229. package/build-style/post-comments-form/style.css +11 -10
  230. package/build-style/query/editor-rtl.css +3 -0
  231. package/build-style/query/editor.css +3 -0
  232. package/build-style/reset-rtl.css +1 -5
  233. package/build-style/reset.css +1 -5
  234. package/build-style/search/style-rtl.css +1 -2
  235. package/build-style/search/style.css +1 -2
  236. package/build-style/social-links/style-rtl.css +91 -91
  237. package/build-style/social-links/style.css +91 -91
  238. package/build-style/style-rtl.css +119 -110
  239. package/build-style/style.css +119 -110
  240. package/build-style/table/theme-rtl.css +2 -2
  241. package/build-style/table/theme.css +2 -2
  242. package/build-style/theme-rtl.css +8 -8
  243. package/build-style/theme.css +8 -8
  244. package/build-style/video/style-rtl.css +1 -1
  245. package/build-style/video/style.css +1 -1
  246. package/build-style/video/theme-rtl.css +2 -2
  247. package/build-style/video/theme.css +2 -2
  248. package/package.json +35 -35
  249. package/src/audio/block.json +4 -0
  250. package/src/audio/edit.js +19 -7
  251. package/src/audio/style.scss +1 -1
  252. package/src/audio/theme.scss +1 -1
  253. package/src/audio/transforms.js +1 -1
  254. package/src/block/block.json +5 -1
  255. package/src/block/edit.js +0 -1
  256. package/src/button/block.json +1 -0
  257. package/src/button/index.php +14 -1
  258. package/src/embed/embed-preview.js +4 -6
  259. package/src/embed/style.scss +1 -1
  260. package/src/embed/theme.scss +1 -1
  261. package/src/file/block.json +4 -0
  262. package/src/file/edit.js +19 -6
  263. package/src/file/transforms.js +1 -2
  264. package/src/gallery/deprecated.js +6 -55
  265. package/src/gallery/edit.js +13 -10
  266. package/src/gallery/gallery-styles.native.scss +0 -2
  267. package/src/gallery/index.js +1 -1
  268. package/src/gallery/save.js +0 -10
  269. package/src/gallery/shared.js +0 -28
  270. package/src/gallery/transforms.js +56 -99
  271. package/src/group/block.json +1 -0
  272. package/src/group/placeholder.js +7 -0
  273. package/src/image/block.json +4 -0
  274. package/src/image/edit.js +10 -19
  275. package/src/image/editor.scss +0 -13
  276. package/src/image/image.js +45 -16
  277. package/src/image/index.php +26 -5
  278. package/src/image/style.scss +11 -1
  279. package/src/image/transforms.js +1 -1
  280. package/src/list-item/block.json +11 -1
  281. package/src/list-item/edit.js +1 -1
  282. package/src/list-item/hooks/use-merge.js +19 -5
  283. package/src/lock-unlock.js +1 -1
  284. package/src/loginout/block.json +3 -0
  285. package/src/media-text/edit.js +3 -2
  286. package/src/media-text/index.php +68 -18
  287. package/src/media-text/style.scss +4 -0
  288. package/src/navigation/index.php +5 -3
  289. package/src/navigation/style.scss +1 -0
  290. package/src/navigation-submenu/edit.js +1 -1
  291. package/src/page-list/convert-to-links-modal.js +1 -1
  292. package/src/page-list/edit.js +1 -1
  293. package/src/paragraph/test/__snapshots__/edit.native.js.snap +30 -0
  294. package/src/paragraph/test/edit.native.js +99 -0
  295. package/src/post-comments-form/style.scss +15 -12
  296. package/src/post-content/block.json +3 -0
  297. package/src/post-date/edit.js +5 -1
  298. package/src/post-date/index.php +9 -3
  299. package/src/post-excerpt/block.json +3 -0
  300. package/src/post-title/block.json +3 -0
  301. package/src/query/edit/inspector-controls/index.js +3 -2
  302. package/src/query/edit/query-toolbar.js +60 -72
  303. package/src/query/editor.scss +4 -0
  304. package/src/query/index.js +40 -0
  305. package/src/quote/edit.js +1 -0
  306. package/src/reset.scss +11 -12
  307. package/src/site-tagline/block.json +1 -0
  308. package/src/site-title/block.json +1 -0
  309. package/src/social-link/edit.js +9 -3
  310. package/src/social-links/style.scss +2 -2
  311. package/src/table/edit.js +11 -24
  312. package/src/table/theme.scss +1 -1
  313. package/src/table-of-contents/block.json +1 -1
  314. package/src/template-part/edit/title-modal.js +1 -1
  315. package/src/template-part/index.php +1 -1
  316. package/src/utils/caption.js +5 -1
  317. package/src/utils/hooks.js +14 -1
  318. package/src/verse/block.json +1 -0
  319. package/src/video/block.json +4 -0
  320. package/src/video/edit.js +23 -8
  321. package/src/video/style.scss +1 -1
  322. package/src/video/theme.scss +1 -1
  323. package/src/video/transforms.js +1 -1
  324. package/tsconfig.tsbuildinfo +1 -1
  325. package/build/gallery/edit-wrapper.js +0 -37
  326. package/build/gallery/edit-wrapper.js.map +0 -1
  327. package/build/gallery/v1/constants.js +0 -10
  328. package/build/gallery/v1/constants.js.map +0 -1
  329. package/build/gallery/v1/edit.js +0 -399
  330. package/build/gallery/v1/edit.js.map +0 -1
  331. package/build/gallery/v1/gallery-button.native.js +0 -55
  332. package/build/gallery/v1/gallery-button.native.js.map +0 -1
  333. package/build/gallery/v1/gallery-image.js +0 -285
  334. package/build/gallery/v1/gallery-image.js.map +0 -1
  335. package/build/gallery/v1/gallery-image.native.js +0 -297
  336. package/build/gallery/v1/gallery-image.native.js.map +0 -1
  337. package/build/gallery/v1/gallery.js +0 -112
  338. package/build/gallery/v1/gallery.js.map +0 -1
  339. package/build/gallery/v1/gallery.native.js +0 -139
  340. package/build/gallery/v1/gallery.native.js.map +0 -1
  341. package/build/gallery/v1/save.js +0 -81
  342. package/build/gallery/v1/save.js.map +0 -1
  343. package/build/gallery/v1/shared.js +0 -17
  344. package/build/gallery/v1/shared.js.map +0 -1
  345. package/build/gallery/v1/tiles.native.js +0 -83
  346. package/build/gallery/v1/tiles.native.js.map +0 -1
  347. package/build/utils/constants.js +0 -15
  348. package/build/utils/constants.js.map +0 -1
  349. package/build-module/gallery/edit-wrapper.js +0 -31
  350. package/build-module/gallery/edit-wrapper.js.map +0 -1
  351. package/build-module/gallery/v1/constants.js +0 -4
  352. package/build-module/gallery/v1/constants.js.map +0 -1
  353. package/build-module/gallery/v1/edit.js +0 -393
  354. package/build-module/gallery/v1/edit.js.map +0 -1
  355. package/build-module/gallery/v1/gallery-button.native.js +0 -46
  356. package/build-module/gallery/v1/gallery-button.native.js.map +0 -1
  357. package/build-module/gallery/v1/gallery-image.js +0 -279
  358. package/build-module/gallery/v1/gallery-image.js.map +0 -1
  359. package/build-module/gallery/v1/gallery-image.native.js +0 -291
  360. package/build-module/gallery/v1/gallery-image.native.js.map +0 -1
  361. package/build-module/gallery/v1/gallery.js +0 -104
  362. package/build-module/gallery/v1/gallery.js.map +0 -1
  363. package/build-module/gallery/v1/gallery.native.js +0 -131
  364. package/build-module/gallery/v1/gallery.native.js.map +0 -1
  365. package/build-module/gallery/v1/save.js +0 -74
  366. package/build-module/gallery/v1/save.js.map +0 -1
  367. package/build-module/gallery/v1/shared.js +0 -10
  368. package/build-module/gallery/v1/shared.js.map +0 -1
  369. package/build-module/gallery/v1/tiles.native.js +0 -75
  370. package/build-module/gallery/v1/tiles.native.js.map +0 -1
  371. package/build-module/utils/constants.js +0 -9
  372. package/build-module/utils/constants.js.map +0 -1
  373. package/src/gallery/edit-wrapper.js +0 -27
  374. package/src/gallery/v1/constants.js +0 -3
  375. package/src/gallery/v1/edit.js +0 -450
  376. package/src/gallery/v1/gallery-button.native.js +0 -47
  377. package/src/gallery/v1/gallery-image-style.native.scss +0 -109
  378. package/src/gallery/v1/gallery-image.js +0 -293
  379. package/src/gallery/v1/gallery-image.native.js +0 -348
  380. package/src/gallery/v1/gallery-styles.native.scss +0 -8
  381. package/src/gallery/v1/gallery.js +0 -125
  382. package/src/gallery/v1/gallery.native.js +0 -162
  383. package/src/gallery/v1/save.js +0 -98
  384. package/src/gallery/v1/shared.js +0 -19
  385. package/src/gallery/v1/tiles-styles.native.scss +0 -11
  386. package/src/gallery/v1/tiles.native.js +0 -79
  387. package/src/utils/constants.js +0 -8
@@ -14,6 +14,7 @@ import {
14
14
  ToggleControl,
15
15
  RangeControl,
16
16
  Spinner,
17
+ withNotices,
17
18
  } from '@wordpress/components';
18
19
  import {
19
20
  store as blockEditorStore,
@@ -237,7 +238,7 @@ function GalleryEdit( props ) {
237
238
  return (
238
239
  ALLOWED_MEDIA_TYPES.some(
239
240
  ( mediaType ) => mediaTypeSelector?.indexOf( mediaType ) === 0
240
- ) || file.url?.indexOf( 'blob:' ) === 0
241
+ ) || file.blob
241
242
  );
242
243
  }
243
244
 
@@ -249,9 +250,9 @@ function GalleryEdit( props ) {
249
250
  const imageArray = newFileUploads
250
251
  ? Array.from( selectedImages ).map( ( file ) => {
251
252
  if ( ! file.url ) {
252
- return pickRelevantMediaFiles( {
253
- url: createBlobURL( file ),
254
- } );
253
+ return {
254
+ blob: createBlobURL( file ),
255
+ };
255
256
  }
256
257
 
257
258
  return file;
@@ -271,9 +272,9 @@ function GalleryEdit( props ) {
271
272
  .filter( ( file ) => file.url || isValidFileType( file ) )
272
273
  .map( ( file ) => {
273
274
  if ( ! file.url ) {
274
- return pickRelevantMediaFiles( {
275
- url: createBlobURL( file ),
276
- } );
275
+ return {
276
+ blob: file.blob || createBlobURL( file ),
277
+ };
277
278
  }
278
279
 
279
280
  return file;
@@ -307,6 +308,7 @@ function GalleryEdit( props ) {
307
308
  const newBlocks = newImageList.map( ( image ) => {
308
309
  return createBlock( 'core/image', {
309
310
  id: image.id,
311
+ blob: image.blob,
310
312
  url: image.url,
311
313
  caption: image.caption,
312
314
  alt: image.alt,
@@ -632,6 +634,7 @@ function GalleryEdit( props ) {
632
634
  </>
633
635
  );
634
636
  }
635
- export default compose( [ withViewportMatch( { isNarrow: '< small' } ) ] )(
636
- GalleryEdit
637
- );
637
+ export default compose( [
638
+ withNotices,
639
+ withViewportMatch( { isNarrow: '< small' } ),
640
+ ] )( GalleryEdit );
@@ -1,5 +1,3 @@
1
- @import "./v1/gallery-styles.native.scss";
2
-
3
1
  .galleryAppender {
4
2
  padding-top: $grid-unit-20;
5
3
  }
@@ -8,7 +8,7 @@ import { gallery as icon } from '@wordpress/icons';
8
8
  */
9
9
  import initBlock from '../utils/init-block';
10
10
  import deprecated from './deprecated';
11
- import edit from './edit-wrapper';
11
+ import edit from './edit';
12
12
  import metadata from './block.json';
13
13
  import save from './save';
14
14
  import transforms from './transforms';
@@ -13,17 +13,7 @@ import {
13
13
  __experimentalGetElementClassName,
14
14
  } from '@wordpress/block-editor';
15
15
 
16
- /**
17
- * Internal dependencies
18
- */
19
- import saveWithoutInnerBlocks from './v1/save';
20
- import { isGalleryV2Enabled } from './shared';
21
-
22
16
  export default function saveWithInnerBlocks( { attributes } ) {
23
- if ( ! isGalleryV2Enabled() ) {
24
- return saveWithoutInnerBlocks( { attributes } );
25
- }
26
-
27
17
  const { caption, columns, imageCrop } = attributes;
28
18
 
29
19
  const className = clsx( 'has-nested-images', {
@@ -1,8 +1,3 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { Platform } from '@wordpress/element';
5
-
6
1
  export function defaultColumnsNumber( imageCount ) {
7
2
  return imageCount ? Math.min( 3, imageCount ) : 3;
8
3
  }
@@ -27,26 +22,3 @@ export const pickRelevantMediaFiles = ( image, sizeSlug = 'large' ) => {
27
22
  }
28
23
  return imageProps;
29
24
  };
30
-
31
- function getGalleryBlockV2Enabled() {
32
- // We want to fail early here, at least during beta testing phase, to ensure
33
- // there aren't instances where undefined values cause false negatives.
34
- if ( ! window.wp || typeof window.wp.galleryBlockV2Enabled !== 'boolean' ) {
35
- throw 'window.wp.galleryBlockV2Enabled is not defined';
36
- }
37
- return window.wp.galleryBlockV2Enabled;
38
- }
39
-
40
- /**
41
- * The new gallery block format is not compatible with the use_BalanceTags option
42
- * in WP versions <= 5.8 https://core.trac.wordpress.org/ticket/54130. The
43
- * window.wp.galleryBlockV2Enabled flag is set in lib/compat.php. This method
44
- * can be removed when minimum supported WP version >=5.9.
45
- */
46
- export function isGalleryV2Enabled() {
47
- if ( Platform.isNative ) {
48
- return getGalleryBlockV2Enabled();
49
- }
50
-
51
- return true;
52
- }
@@ -13,7 +13,6 @@ import {
13
13
  LINK_DESTINATION_NONE,
14
14
  LINK_DESTINATION_MEDIA,
15
15
  } from './constants';
16
- import { pickRelevantMediaFiles, isGalleryV2Enabled } from './shared';
17
16
 
18
17
  const parseShortcodeIds = ( ids ) => {
19
18
  if ( ! ids ) {
@@ -39,7 +38,6 @@ const parseShortcodeIds = ( ids ) => {
39
38
  */
40
39
  function updateThirdPartyTransformToGallery( block ) {
41
40
  if (
42
- isGalleryV2Enabled() &&
43
41
  block.name === 'core/gallery' &&
44
42
  block.attributes?.images.length > 0
45
43
  ) {
@@ -137,37 +135,21 @@ const transforms = {
137
135
 
138
136
  const validImages = attributes.filter( ( { url } ) => url );
139
137
 
140
- if ( isGalleryV2Enabled() ) {
141
- const innerBlocks = validImages.map( ( image ) => {
142
- // Gallery images can't currently be resized so make sure height and width are undefined.
143
- image.width = undefined;
144
- image.height = undefined;
145
- return createBlock( 'core/image', image );
146
- } );
147
-
148
- return createBlock(
149
- 'core/gallery',
150
- {
151
- align,
152
- sizeSlug,
153
- },
154
- innerBlocks
155
- );
156
- }
157
-
158
- return createBlock( 'core/gallery', {
159
- images: validImages.map(
160
- ( { id, url, alt, caption } ) => ( {
161
- id: id.toString(),
162
- url,
163
- alt,
164
- caption,
165
- } )
166
- ),
167
- ids: validImages.map( ( { id } ) => parseInt( id, 10 ) ),
168
- align,
169
- sizeSlug,
138
+ const innerBlocks = validImages.map( ( image ) => {
139
+ // Gallery images can't currently be resized so make sure height and width are undefined.
140
+ image.width = undefined;
141
+ image.height = undefined;
142
+ return createBlock( 'core/image', image );
170
143
  } );
144
+
145
+ return createBlock(
146
+ 'core/gallery',
147
+ {
148
+ align,
149
+ sizeSlug,
150
+ },
151
+ innerBlocks
152
+ );
171
153
  },
172
154
  },
173
155
  {
@@ -220,23 +202,13 @@ const transforms = {
220
202
  );
221
203
  },
222
204
  transform( files ) {
223
- if ( isGalleryV2Enabled() ) {
224
- const innerBlocks = files.map( ( file ) =>
225
- createBlock( 'core/image', {
226
- url: createBlobURL( file ),
227
- } )
228
- );
205
+ const innerBlocks = files.map( ( file ) =>
206
+ createBlock( 'core/image', {
207
+ blob: createBlobURL( file ),
208
+ } )
209
+ );
229
210
 
230
- return createBlock( 'core/gallery', {}, innerBlocks );
231
- }
232
- const block = createBlock( 'core/gallery', {
233
- images: files.map( ( file ) =>
234
- pickRelevantMediaFiles( {
235
- url: createBlobURL( file ),
236
- } )
237
- ),
238
- } );
239
- return block;
211
+ return createBlock( 'core/gallery', {}, innerBlocks );
240
212
  },
241
213
  },
242
214
  ],
@@ -244,57 +216,42 @@ const transforms = {
244
216
  {
245
217
  type: 'block',
246
218
  blocks: [ 'core/image' ],
247
- transform: ( { align, images, ids, sizeSlug }, innerBlocks ) => {
248
- if ( isGalleryV2Enabled() ) {
249
- if ( innerBlocks.length > 0 ) {
250
- return innerBlocks.map(
251
- ( {
252
- attributes: {
253
- url,
254
- alt,
255
- caption,
256
- title,
257
- href,
258
- rel,
259
- linkClass,
260
- id,
261
- sizeSlug: imageSizeSlug,
262
- linkDestination,
263
- linkTarget,
264
- anchor,
265
- className,
266
- },
267
- } ) =>
268
- createBlock( 'core/image', {
269
- align,
270
- url,
271
- alt,
272
- caption,
273
- title,
274
- href,
275
- rel,
276
- linkClass,
277
- id,
278
- sizeSlug: imageSizeSlug,
279
- linkDestination,
280
- linkTarget,
281
- anchor,
282
- className,
283
- } )
284
- );
285
- }
286
- return createBlock( 'core/image', { align } );
287
- }
288
- if ( images.length > 0 ) {
289
- return images.map( ( { url, alt, caption }, index ) =>
290
- createBlock( 'core/image', {
291
- id: ids[ index ],
292
- url,
293
- alt,
294
- caption,
295
- align,
296
- sizeSlug,
297
- } )
219
+ transform: ( { align }, innerBlocks ) => {
220
+ if ( innerBlocks.length > 0 ) {
221
+ return innerBlocks.map(
222
+ ( {
223
+ attributes: {
224
+ url,
225
+ alt,
226
+ caption,
227
+ title,
228
+ href,
229
+ rel,
230
+ linkClass,
231
+ id,
232
+ sizeSlug: imageSizeSlug,
233
+ linkDestination,
234
+ linkTarget,
235
+ anchor,
236
+ className,
237
+ },
238
+ } ) =>
239
+ createBlock( 'core/image', {
240
+ align,
241
+ url,
242
+ alt,
243
+ caption,
244
+ title,
245
+ href,
246
+ rel,
247
+ linkClass,
248
+ id,
249
+ sizeSlug: imageSizeSlug,
250
+ linkDestination,
251
+ linkTarget,
252
+ anchor,
253
+ className,
254
+ } )
298
255
  );
299
256
  }
300
257
  return createBlock( 'core/image', { align } );
@@ -45,6 +45,7 @@
45
45
  "text": true
46
46
  }
47
47
  },
48
+ "shadow": true,
48
49
  "spacing": {
49
50
  "margin": [ "top", "bottom" ],
50
51
  "padding": true,
@@ -139,6 +139,13 @@ function GroupPlaceHolder( { name, onSelect } ) {
139
139
  const blockProps = useBlockProps( {
140
140
  className: 'wp-block-group__placeholder',
141
141
  } );
142
+
143
+ useEffect( () => {
144
+ if ( variations && variations.length === 1 ) {
145
+ onSelect( variations[ 0 ] );
146
+ }
147
+ }, [ onSelect, variations ] );
148
+
142
149
  return (
143
150
  <div { ...blockProps }>
144
151
  <Placeholder
@@ -9,6 +9,10 @@
9
9
  "keywords": [ "img", "photo", "picture" ],
10
10
  "textdomain": "default",
11
11
  "attributes": {
12
+ "blob": {
13
+ "type": "string",
14
+ "__experimentalRole": "local"
15
+ },
12
16
  "url": {
13
17
  "type": "string",
14
18
  "source": "attribute",
package/src/image/edit.js CHANGED
@@ -56,17 +56,6 @@ export const pickRelevantMediaFiles = ( image, size ) => {
56
56
  return imageProps;
57
57
  };
58
58
 
59
- /**
60
- * Is the URL a temporary blob URL? A blob URL is one that is used temporarily
61
- * while the image is being uploaded and will not have an id yet allocated.
62
- *
63
- * @param {number=} id The id of the image.
64
- * @param {string=} url The url of the image.
65
- *
66
- * @return {boolean} Is the URL a Blob URL
67
- */
68
- const isTemporaryImage = ( id, url ) => ! id && isBlobURL( url );
69
-
70
59
  /**
71
60
  * Is the url for the image hosted externally. An externally hosted image has no
72
61
  * id and is not a blob url.
@@ -118,9 +107,7 @@ export function ImageEdit( {
118
107
  align,
119
108
  metadata,
120
109
  } = attributes;
121
- const [ temporaryURL, setTemporaryURL ] = useState( () => {
122
- return isTemporaryImage( id, url ) ? url : undefined;
123
- } );
110
+ const [ temporaryURL, setTemporaryURL ] = useState( attributes.blob );
124
111
 
125
112
  const altRef = useRef();
126
113
  useEffect( () => {
@@ -157,8 +144,8 @@ export function ImageEdit( {
157
144
  src: undefined,
158
145
  id: undefined,
159
146
  url: undefined,
147
+ blob: undefined,
160
148
  } );
161
- setTemporaryURL( undefined );
162
149
  }
163
150
 
164
151
  function onSelectImage( media ) {
@@ -169,7 +156,9 @@ export function ImageEdit( {
169
156
  id: undefined,
170
157
  title: undefined,
171
158
  caption: undefined,
159
+ blob: undefined,
172
160
  } );
161
+ setTemporaryURL();
173
162
 
174
163
  return;
175
164
  }
@@ -179,8 +168,6 @@ export function ImageEdit( {
179
168
  return;
180
169
  }
181
170
 
182
- setTemporaryURL();
183
-
184
171
  const { imageDefaultSize } = getSettings();
185
172
 
186
173
  // Try to use the previous selected image size if its available
@@ -254,24 +241,28 @@ export function ImageEdit( {
254
241
  mediaAttributes.href = href;
255
242
 
256
243
  setAttributes( {
244
+ blob: undefined,
257
245
  ...mediaAttributes,
258
246
  ...additionalAttributes,
259
247
  linkDestination,
260
248
  } );
249
+ setTemporaryURL();
261
250
  }
262
251
 
263
252
  function onSelectURL( newURL ) {
264
253
  if ( newURL !== url ) {
265
254
  setAttributes( {
255
+ blob: undefined,
266
256
  url: newURL,
267
257
  id: undefined,
268
258
  sizeSlug: getSettings().imageDefaultSize,
269
259
  } );
260
+ setTemporaryURL();
270
261
  }
271
262
  }
272
263
 
273
264
  useUploadMediaFromBlobURL( {
274
- url,
265
+ url: temporaryURL,
275
266
  allowedTypes: ALLOWED_MEDIA_TYPES,
276
267
  onChange: onSelectImage,
277
268
  onError: onUploadError,
@@ -292,7 +283,7 @@ export function ImageEdit( {
292
283
  const shadowProps = getShadowClassesAndStyles( attributes );
293
284
 
294
285
  const classes = clsx( className, {
295
- 'is-transient': temporaryURL,
286
+ 'is-transient': !! temporaryURL,
296
287
  'is-resized': !! width || !! height,
297
288
  [ `size-${ sizeSlug }` ]: sizeSlug,
298
289
  'has-custom-border':
@@ -176,19 +176,6 @@ figure.wp-block-image:not(.wp-block) {
176
176
  }
177
177
  }
178
178
 
179
- .wp-block-image__aspect-ratio {
180
- height: $grid-unit-60 - $border-width - $border-width;
181
- margin-bottom: -$grid-unit-10;
182
- display: flex;
183
- align-items: center;
184
-
185
- .components-button {
186
- width: $button-size;
187
- padding-left: 0;
188
- padding-right: 0;
189
- }
190
- }
191
-
192
179
  .wp-block-image__toolbar_content_textarea {
193
180
  // Corresponds to the size of the textarea in the block inspector.
194
181
  width: 250px;
@@ -49,7 +49,7 @@ import { Caption } from '../utils/caption';
49
49
  /**
50
50
  * Module constants
51
51
  */
52
- import { TOOLSPANEL_DROPDOWNMENU_PROPS } from '../utils/constants';
52
+ import { useToolsPanelDropdownMenuProps } from '../utils/hooks';
53
53
  import { MIN_SIZE, ALLOWED_MEDIA_TYPES } from './constants';
54
54
  import { evalAspectRatio } from './utils';
55
55
 
@@ -182,8 +182,7 @@ export default function Image( {
182
182
  allowResize &&
183
183
  hasNonContentControls &&
184
184
  ! isWideAligned &&
185
- isLargeViewport &&
186
- parentLayoutType !== 'grid';
185
+ isLargeViewport;
187
186
  const imageSizeOptions = imageSizes
188
187
  .filter(
189
188
  ( { slug } ) => image?.media_details?.sizes?.[ slug ]?.source_url
@@ -373,6 +372,8 @@ export default function Image( {
373
372
  const lightboxChecked =
374
373
  !! lightbox?.enabled || ( ! lightbox && !! lightboxSetting?.enabled );
375
374
 
375
+ const dropdownMenuProps = useToolsPanelDropdownMenuProps();
376
+
376
377
  const dimensionsControl = (
377
378
  <DimensionsTool
378
379
  value={ { width, height, scale, aspectRatio } }
@@ -403,6 +404,20 @@ export default function Image( {
403
404
  />
404
405
  );
405
406
 
407
+ const aspectRatioControl = (
408
+ <DimensionsTool
409
+ value={ { aspectRatio } }
410
+ onChange={ ( { aspectRatio: newAspectRatio } ) => {
411
+ setAttributes( {
412
+ aspectRatio: newAspectRatio,
413
+ scale: 'cover',
414
+ } );
415
+ } }
416
+ defaultAspectRatio="auto"
417
+ tools={ [ 'aspectRatio' ] }
418
+ />
419
+ );
420
+
406
421
  const resetAll = () => {
407
422
  setAttributes( {
408
423
  alt: undefined,
@@ -419,13 +434,19 @@ export default function Image( {
419
434
  <ToolsPanel
420
435
  label={ __( 'Settings' ) }
421
436
  resetAll={ resetAll }
422
- dropdownMenuProps={ TOOLSPANEL_DROPDOWNMENU_PROPS }
437
+ dropdownMenuProps={ dropdownMenuProps }
423
438
  >
424
- { isResizable && dimensionsControl }
439
+ { isResizable &&
440
+ ( parentLayoutType === 'grid'
441
+ ? aspectRatioControl
442
+ : dimensionsControl ) }
425
443
  </ToolsPanel>
426
444
  </InspectorControls>
427
445
  );
428
446
 
447
+ const arePatternOverridesEnabled =
448
+ metadata?.bindings?.__default?.source === 'core/pattern-overrides';
449
+
429
450
  const {
430
451
  lockUrlControls = false,
431
452
  lockHrefControls = false,
@@ -440,16 +461,12 @@ export default function Image( {
440
461
  return {};
441
462
  }
442
463
  const { getBlockBindingsSource } = unlock( select( blocksStore ) );
443
- const { getBlockParentsByBlockName } = unlock(
444
- select( blockEditorStore )
445
- );
446
464
  const {
447
465
  url: urlBinding,
448
466
  alt: altBinding,
449
467
  title: titleBinding,
450
468
  } = metadata?.bindings || {};
451
- const hasParentPattern =
452
- getBlockParentsByBlockName( clientId, 'core/block' ).length > 0;
469
+ const hasParentPattern = !! context[ 'pattern/overrides' ];
453
470
  const urlBindingSource = getBlockBindingsSource(
454
471
  urlBinding?.source
455
472
  );
@@ -470,7 +487,7 @@ export default function Image( {
470
487
  lockHrefControls:
471
488
  // Disable editing the link of the URL if the image is inside a pattern instance.
472
489
  // This is a temporary solution until we support overriding the link on the frontend.
473
- hasParentPattern,
490
+ hasParentPattern || arePatternOverridesEnabled,
474
491
  lockCaption:
475
492
  // Disable editing the caption if the image is inside a pattern instance.
476
493
  // This is a temporary solution until we support overriding the caption on the frontend.
@@ -505,7 +522,12 @@ export default function Image( {
505
522
  : __( 'Connected to dynamic data' ),
506
523
  };
507
524
  },
508
- [ clientId, isSingleSelected, metadata?.bindings ]
525
+ [
526
+ arePatternOverridesEnabled,
527
+ context,
528
+ isSingleSelected,
529
+ metadata?.bindings,
530
+ ]
509
531
  );
510
532
 
511
533
  const showUrlInput =
@@ -688,7 +710,7 @@ export default function Image( {
688
710
  <ToolsPanel
689
711
  label={ __( 'Settings' ) }
690
712
  resetAll={ resetAll }
691
- dropdownMenuProps={ TOOLSPANEL_DROPDOWNMENU_PROPS }
713
+ dropdownMenuProps={ dropdownMenuProps }
692
714
  >
693
715
  { isSingleSelected && (
694
716
  <ToolsPanelItem
@@ -732,7 +754,10 @@ export default function Image( {
732
754
  />
733
755
  </ToolsPanelItem>
734
756
  ) }
735
- { isResizable && dimensionsControl }
757
+ { isResizable &&
758
+ ( parentLayoutType === 'grid'
759
+ ? aspectRatioControl
760
+ : dimensionsControl ) }
736
761
  { !! imageSizeOptions.length && (
737
762
  <ResolutionTool
738
763
  value={ sizeSlug }
@@ -842,7 +867,7 @@ export default function Image( {
842
867
  />
843
868
  </ImageWrapper>
844
869
  );
845
- } else if ( ! isResizable ) {
870
+ } else if ( ! isResizable || parentLayoutType === 'grid' ) {
846
871
  img = (
847
872
  <div style={ { width, height, aspectRatio } }>
848
873
  <ImageWrapper href={ href }>{ img }</ImageWrapper>
@@ -971,7 +996,11 @@ export default function Image( {
971
996
  isSelected={ isSingleSelected }
972
997
  insertBlocksAfter={ insertBlocksAfter }
973
998
  label={ __( 'Image caption text' ) }
974
- showToolbarButton={ isSingleSelected && hasNonContentControls }
999
+ showToolbarButton={
1000
+ isSingleSelected &&
1001
+ hasNonContentControls &&
1002
+ ! arePatternOverridesEnabled
1003
+ }
975
1004
  readOnly={ lockCaption }
976
1005
  />
977
1006
  </>
@@ -28,12 +28,33 @@ function render_block_core_image( $attributes, $content, $block ) {
28
28
  return '';
29
29
  }
30
30
 
31
+ $has_id_binding = isset( $attributes['metadata']['bindings']['id'] ) && isset( $attributes['id'] );
32
+
33
+ // Ensure the `wp-image-id` classname on the image block supports block bindings.
34
+ if ( $has_id_binding ) {
35
+ // If there's a mismatch with the 'wp-image-' class and the actual id, the id was
36
+ // probably overridden by block bindings. Update it to the correct value.
37
+ // See https://github.com/WordPress/gutenberg/issues/62886 for why this is needed.
38
+ $id = $attributes['id'];
39
+ $image_classnames = $p->get_attribute( 'class' );
40
+ $class_with_binding_value = "wp-image-$id";
41
+ if ( is_string( $image_classnames ) && ! str_contains( $image_classnames, $class_with_binding_value ) ) {
42
+ $image_classnames = preg_replace( '/wp-image-(\d+)/', $class_with_binding_value, $image_classnames );
43
+ $p->set_attribute( 'class', $image_classnames );
44
+ }
45
+ }
46
+
47
+ // For backwards compatibility, the data-id html attribute is only set for
48
+ // image blocks nested in a gallery. Detect if the image is in a gallery by
49
+ // checking the data-id attribute.
50
+ // See the `block_core_gallery_data_id_backcompatibility` function.
31
51
  if ( isset( $attributes['data-id'] ) ) {
32
- // Adds the data-id="$id" attribute to the img element to provide backwards
33
- // compatibility for the Gallery Block, which now wraps Image Blocks within
34
- // innerBlocks. The data-id attribute is added in a core/gallery
35
- // `render_block_data` hook.
36
- $p->set_attribute( 'data-id', $attributes['data-id'] );
52
+ // If there's a binding for the `id`, the `id` attribute is used for the
53
+ // value, since `data-id` does not support block bindings.
54
+ // Else the `data-id` is used for backwards compatibility, since
55
+ // third parties may be filtering its value.
56
+ $data_id = $has_id_binding ? $attributes['id'] : $attributes['data-id'];
57
+ $p->set_attribute( 'data-id', $data_id );
37
58
  }
38
59
 
39
60
  $link_destination = isset( $attributes['linkDestination'] ) ? $attributes['linkDestination'] : 'none';