@wordpress/block-library 8.13.0 → 8.14.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 (366) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/archives/index.js +5 -1
  3. package/build/archives/index.js.map +1 -1
  4. package/build/audio/index.js +5 -1
  5. package/build/audio/index.js.map +1 -1
  6. package/build/avatar/index.js +1 -1
  7. package/build/block/edit.js +1 -1
  8. package/build/block/edit.js.map +1 -1
  9. package/build/block/edit.native.js +6 -9
  10. package/build/block/edit.native.js.map +1 -1
  11. package/build/buttons/edit.js +5 -1
  12. package/build/buttons/edit.js.map +1 -1
  13. package/build/categories/index.js +5 -1
  14. package/build/categories/index.js.map +1 -1
  15. package/build/code/index.js +5 -1
  16. package/build/code/index.js.map +1 -1
  17. package/build/column/index.js +1 -0
  18. package/build/column/index.js.map +1 -1
  19. package/build/comments/index.js +1 -0
  20. package/build/comments/index.js.map +1 -1
  21. package/build/cover/edit/inspector-controls.js +2 -1
  22. package/build/cover/edit/inspector-controls.js.map +1 -1
  23. package/build/cover/index.js +1 -0
  24. package/build/cover/index.js.map +1 -1
  25. package/build/details/index.js +5 -1
  26. package/build/details/index.js.map +1 -1
  27. package/build/embed/util.js +9 -8
  28. package/build/embed/util.js.map +1 -1
  29. package/build/file/index.js +2 -1
  30. package/build/file/index.js.map +1 -1
  31. package/build/file/view.js +15 -1
  32. package/build/file/view.js.map +1 -1
  33. package/build/gallery/index.js +3 -1
  34. package/build/gallery/index.js.map +1 -1
  35. package/build/group/index.js +1 -0
  36. package/build/group/index.js.map +1 -1
  37. package/build/heading/index.js +5 -1
  38. package/build/heading/index.js.map +1 -1
  39. package/build/heading/transforms.js +5 -1
  40. package/build/heading/transforms.js.map +1 -1
  41. package/build/image/deprecated.js +453 -175
  42. package/build/image/deprecated.js.map +1 -1
  43. package/build/image/edit.js +0 -4
  44. package/build/image/edit.js.map +1 -1
  45. package/build/image/image.js +96 -43
  46. package/build/image/image.js.map +1 -1
  47. package/build/image/index.js +6 -0
  48. package/build/image/index.js.map +1 -1
  49. package/build/image/save.js +8 -1
  50. package/build/image/save.js.map +1 -1
  51. package/build/image/utils.js +18 -0
  52. package/build/image/utils.js.map +1 -1
  53. package/build/image/{interactivity.js → view-interactivity.js} +86 -44
  54. package/build/image/view-interactivity.js.map +1 -0
  55. package/build/index.js +12 -3
  56. package/build/index.js.map +1 -1
  57. package/build/list/index.js +5 -1
  58. package/build/list/index.js.map +1 -1
  59. package/build/list-item/utils.js +6 -1
  60. package/build/list-item/utils.js.map +1 -1
  61. package/build/media-text/index.js +1 -0
  62. package/build/media-text/index.js.map +1 -1
  63. package/build/missing/edit.js +22 -8
  64. package/build/missing/edit.js.map +1 -1
  65. package/build/navigation/edit/index.js +1 -1
  66. package/build/navigation/edit/index.js.map +1 -1
  67. package/build/navigation/edit/menu-inspector-controls.js +0 -1
  68. package/build/navigation/edit/menu-inspector-controls.js.map +1 -1
  69. package/build/navigation/index.js +3 -2
  70. package/build/navigation/index.js.map +1 -1
  71. package/build/navigation/view.js +174 -50
  72. package/build/navigation/view.js.map +1 -1
  73. package/build/navigation-link/edit.js +0 -11
  74. package/build/navigation-link/edit.js.map +1 -1
  75. package/build/navigation-link/link-ui.js +12 -2
  76. package/build/navigation-link/link-ui.js.map +1 -1
  77. package/build/page-list/convert-to-links-modal.js +3 -3
  78. package/build/page-list/convert-to-links-modal.js.map +1 -1
  79. package/build/page-list/edit.js +34 -39
  80. package/build/page-list/edit.js.map +1 -1
  81. package/build/page-list/use-convert-to-navigation-links.js +2 -15
  82. package/build/page-list/use-convert-to-navigation-links.js.map +1 -1
  83. package/build/paragraph/index.js +1 -0
  84. package/build/paragraph/index.js.map +1 -1
  85. package/build/paragraph/transforms.js +1 -0
  86. package/build/paragraph/transforms.js.map +1 -1
  87. package/build/post-comments-form/index.js +1 -0
  88. package/build/post-comments-form/index.js.map +1 -1
  89. package/build/post-navigation-link/index.js +1 -0
  90. package/build/post-navigation-link/index.js.map +1 -1
  91. package/build/post-time-to-read/index.js +5 -1
  92. package/build/post-time-to-read/index.js.map +1 -1
  93. package/build/query-pagination-numbers/index.js +1 -1
  94. package/build/quote/index.js +1 -0
  95. package/build/quote/index.js.map +1 -1
  96. package/build/site-logo/index.js +5 -1
  97. package/build/site-logo/index.js.map +1 -1
  98. package/build/site-tagline/icon.js +1 -1
  99. package/build/site-tagline/icon.js.map +1 -1
  100. package/build/site-tagline/index.js +5 -1
  101. package/build/site-tagline/index.js.map +1 -1
  102. package/build/site-title/index.js +5 -1
  103. package/build/site-title/index.js.map +1 -1
  104. package/build/social-links/index.js +3 -1
  105. package/build/social-links/index.js.map +1 -1
  106. package/build/table/index.js +5 -1
  107. package/build/table/index.js.map +1 -1
  108. package/build/term-description/index.js +1 -0
  109. package/build/term-description/index.js.map +1 -1
  110. package/build/verse/index.js +5 -1
  111. package/build/verse/index.js.map +1 -1
  112. package/build/video/deprecated.js +5 -1
  113. package/build/video/deprecated.js.map +1 -1
  114. package/build/video/index.js +5 -1
  115. package/build/video/index.js.map +1 -1
  116. package/build-module/archives/index.js +5 -1
  117. package/build-module/archives/index.js.map +1 -1
  118. package/build-module/audio/index.js +5 -1
  119. package/build-module/audio/index.js.map +1 -1
  120. package/build-module/avatar/index.js +1 -1
  121. package/build-module/block/edit.js +1 -1
  122. package/build-module/block/edit.js.map +1 -1
  123. package/build-module/block/edit.native.js +7 -9
  124. package/build-module/block/edit.native.js.map +1 -1
  125. package/build-module/buttons/edit.js +5 -1
  126. package/build-module/buttons/edit.js.map +1 -1
  127. package/build-module/categories/index.js +5 -1
  128. package/build-module/categories/index.js.map +1 -1
  129. package/build-module/code/index.js +5 -1
  130. package/build-module/code/index.js.map +1 -1
  131. package/build-module/column/index.js +1 -0
  132. package/build-module/column/index.js.map +1 -1
  133. package/build-module/comments/index.js +1 -0
  134. package/build-module/comments/index.js.map +1 -1
  135. package/build-module/cover/edit/inspector-controls.js +2 -1
  136. package/build-module/cover/edit/inspector-controls.js.map +1 -1
  137. package/build-module/cover/index.js +1 -0
  138. package/build-module/cover/index.js.map +1 -1
  139. package/build-module/details/index.js +5 -1
  140. package/build-module/details/index.js.map +1 -1
  141. package/build-module/embed/util.js +6 -6
  142. package/build-module/embed/util.js.map +1 -1
  143. package/build-module/file/index.js +2 -1
  144. package/build-module/file/index.js.map +1 -1
  145. package/build-module/file/view.js +15 -2
  146. package/build-module/file/view.js.map +1 -1
  147. package/build-module/gallery/index.js +3 -1
  148. package/build-module/gallery/index.js.map +1 -1
  149. package/build-module/group/index.js +1 -0
  150. package/build-module/group/index.js.map +1 -1
  151. package/build-module/heading/index.js +5 -1
  152. package/build-module/heading/index.js.map +1 -1
  153. package/build-module/heading/transforms.js +5 -1
  154. package/build-module/heading/transforms.js.map +1 -1
  155. package/build-module/image/deprecated.js +454 -176
  156. package/build-module/image/deprecated.js.map +1 -1
  157. package/build-module/image/edit.js +0 -4
  158. package/build-module/image/edit.js.map +1 -1
  159. package/build-module/image/image.js +96 -46
  160. package/build-module/image/image.js.map +1 -1
  161. package/build-module/image/index.js +6 -0
  162. package/build-module/image/index.js.map +1 -1
  163. package/build-module/image/save.js +8 -1
  164. package/build-module/image/save.js.map +1 -1
  165. package/build-module/image/utils.js +16 -0
  166. package/build-module/image/utils.js.map +1 -1
  167. package/build-module/image/{interactivity.js → view-interactivity.js} +86 -44
  168. package/build-module/image/view-interactivity.js.map +1 -0
  169. package/build-module/index.js +12 -3
  170. package/build-module/index.js.map +1 -1
  171. package/build-module/list/index.js +5 -1
  172. package/build-module/list/index.js.map +1 -1
  173. package/build-module/list-item/utils.js +6 -1
  174. package/build-module/list-item/utils.js.map +1 -1
  175. package/build-module/media-text/index.js +1 -0
  176. package/build-module/media-text/index.js.map +1 -1
  177. package/build-module/missing/edit.js +22 -8
  178. package/build-module/missing/edit.js.map +1 -1
  179. package/build-module/navigation/edit/index.js +1 -1
  180. package/build-module/navigation/edit/index.js.map +1 -1
  181. package/build-module/navigation/edit/menu-inspector-controls.js +0 -1
  182. package/build-module/navigation/edit/menu-inspector-controls.js.map +1 -1
  183. package/build-module/navigation/index.js +3 -2
  184. package/build-module/navigation/index.js.map +1 -1
  185. package/build-module/navigation/view.js +173 -50
  186. package/build-module/navigation/view.js.map +1 -1
  187. package/build-module/navigation-link/edit.js +1 -12
  188. package/build-module/navigation-link/edit.js.map +1 -1
  189. package/build-module/navigation-link/link-ui.js +13 -3
  190. package/build-module/navigation-link/link-ui.js.map +1 -1
  191. package/build-module/page-list/convert-to-links-modal.js +3 -3
  192. package/build-module/page-list/convert-to-links-modal.js.map +1 -1
  193. package/build-module/page-list/edit.js +34 -39
  194. package/build-module/page-list/edit.js.map +1 -1
  195. package/build-module/page-list/use-convert-to-navigation-links.js +3 -16
  196. package/build-module/page-list/use-convert-to-navigation-links.js.map +1 -1
  197. package/build-module/paragraph/index.js +1 -0
  198. package/build-module/paragraph/index.js.map +1 -1
  199. package/build-module/paragraph/transforms.js +1 -0
  200. package/build-module/paragraph/transforms.js.map +1 -1
  201. package/build-module/post-comments-form/index.js +1 -0
  202. package/build-module/post-comments-form/index.js.map +1 -1
  203. package/build-module/post-navigation-link/index.js +1 -0
  204. package/build-module/post-navigation-link/index.js.map +1 -1
  205. package/build-module/post-time-to-read/index.js +5 -1
  206. package/build-module/post-time-to-read/index.js.map +1 -1
  207. package/build-module/query-pagination-numbers/index.js +1 -1
  208. package/build-module/quote/index.js +1 -0
  209. package/build-module/quote/index.js.map +1 -1
  210. package/build-module/site-logo/index.js +5 -1
  211. package/build-module/site-logo/index.js.map +1 -1
  212. package/build-module/site-tagline/icon.js +1 -1
  213. package/build-module/site-tagline/icon.js.map +1 -1
  214. package/build-module/site-tagline/index.js +5 -1
  215. package/build-module/site-tagline/index.js.map +1 -1
  216. package/build-module/site-title/index.js +5 -1
  217. package/build-module/site-title/index.js.map +1 -1
  218. package/build-module/social-links/index.js +3 -1
  219. package/build-module/social-links/index.js.map +1 -1
  220. package/build-module/table/index.js +5 -1
  221. package/build-module/table/index.js.map +1 -1
  222. package/build-module/term-description/index.js +1 -0
  223. package/build-module/term-description/index.js.map +1 -1
  224. package/build-module/verse/index.js +5 -1
  225. package/build-module/verse/index.js.map +1 -1
  226. package/build-module/video/deprecated.js +5 -1
  227. package/build-module/video/deprecated.js.map +1 -1
  228. package/build-module/video/index.js +5 -1
  229. package/build-module/video/index.js.map +1 -1
  230. package/build-style/footnotes/style-rtl.css +2 -2
  231. package/build-style/footnotes/style.css +2 -2
  232. package/build-style/image/style-rtl.css +16 -2
  233. package/build-style/image/style.css +16 -2
  234. package/build-style/style-rtl.css +18 -4
  235. package/build-style/style.css +18 -4
  236. package/package.json +33 -38
  237. package/src/archives/block.json +5 -1
  238. package/src/audio/block.json +5 -1
  239. package/src/avatar/block.json +1 -1
  240. package/src/block/edit.js +2 -2
  241. package/src/block/edit.native.js +8 -12
  242. package/src/block/test/edit.native.js +4 -4
  243. package/src/buttons/edit.js +2 -2
  244. package/src/categories/block.json +5 -1
  245. package/src/code/block.json +5 -1
  246. package/src/column/block.json +1 -0
  247. package/src/comments/block.json +1 -0
  248. package/src/cover/block.json +1 -0
  249. package/src/cover/edit/inspector-controls.js +1 -0
  250. package/src/details/block.json +5 -1
  251. package/src/embed/util.js +4 -6
  252. package/src/file/block.json +2 -1
  253. package/src/file/index.php +0 -17
  254. package/src/file/view.js +14 -5
  255. package/src/footnotes/index.php +11 -9
  256. package/src/footnotes/style.scss +2 -2
  257. package/src/gallery/block.json +3 -1
  258. package/src/group/block.json +1 -0
  259. package/src/heading/block.json +5 -1
  260. package/src/heading/test/index.native.js +18 -0
  261. package/src/image/block.json +6 -0
  262. package/src/image/deprecated.js +597 -320
  263. package/src/image/edit.js +0 -4
  264. package/src/image/image.js +131 -62
  265. package/src/image/save.js +9 -1
  266. package/src/image/style.scss +15 -2
  267. package/src/image/utils.js +16 -0
  268. package/src/image/{interactivity.js → view-interactivity.js} +99 -50
  269. package/src/index.js +18 -1
  270. package/src/latest-posts/index.php +1 -1
  271. package/src/list/block.json +5 -1
  272. package/src/media-text/block.json +1 -0
  273. package/src/missing/edit.js +31 -11
  274. package/src/navigation/block.json +3 -2
  275. package/src/navigation/edit/index.js +1 -2
  276. package/src/navigation/edit/menu-inspector-controls.js +0 -1
  277. package/src/navigation/index.php +39 -30
  278. package/src/navigation/view.js +189 -67
  279. package/src/navigation-link/edit.js +1 -15
  280. package/src/navigation-link/link-ui.js +14 -2
  281. package/src/navigation-submenu/index.php +2 -12
  282. package/src/page-list/convert-to-links-modal.js +3 -3
  283. package/src/page-list/edit.js +65 -62
  284. package/src/page-list/use-convert-to-navigation-links.js +3 -20
  285. package/src/paragraph/block.json +1 -0
  286. package/src/post-comments-form/block.json +1 -0
  287. package/src/post-navigation-link/block.json +1 -0
  288. package/src/post-time-to-read/block.json +5 -1
  289. package/src/query-pagination-numbers/block.json +1 -1
  290. package/src/quote/block.json +1 -0
  291. package/src/site-logo/block.json +5 -1
  292. package/src/site-tagline/block.json +5 -1
  293. package/src/site-tagline/icon.js +1 -1
  294. package/src/site-title/block.json +5 -1
  295. package/src/social-links/block.json +3 -1
  296. package/src/table/block.json +5 -1
  297. package/src/term-description/block.json +1 -0
  298. package/src/verse/block.json +5 -1
  299. package/src/video/block.json +5 -1
  300. package/build/file/interactivity.js +0 -19
  301. package/build/file/interactivity.js.map +0 -1
  302. package/build/heading/heading-level-icon.js +0 -61
  303. package/build/heading/heading-level-icon.js.map +0 -1
  304. package/build/image/interactivity.js.map +0 -1
  305. package/build/navigation/interactivity.js +0 -167
  306. package/build/navigation/interactivity.js.map +0 -1
  307. package/build/navigation/view-modal.js +0 -64
  308. package/build/navigation/view-modal.js.map +0 -1
  309. package/build/utils/interactivity/constants.js +0 -9
  310. package/build/utils/interactivity/constants.js.map +0 -1
  311. package/build/utils/interactivity/directives.js +0 -222
  312. package/build/utils/interactivity/directives.js.map +0 -1
  313. package/build/utils/interactivity/hooks.js +0 -159
  314. package/build/utils/interactivity/hooks.js.map +0 -1
  315. package/build/utils/interactivity/hydration.js +0 -34
  316. package/build/utils/interactivity/hydration.js.map +0 -1
  317. package/build/utils/interactivity/index.js +0 -32
  318. package/build/utils/interactivity/index.js.map +0 -1
  319. package/build/utils/interactivity/portals.js +0 -108
  320. package/build/utils/interactivity/portals.js.map +0 -1
  321. package/build/utils/interactivity/store.js +0 -66
  322. package/build/utils/interactivity/store.js.map +0 -1
  323. package/build/utils/interactivity/utils.js +0 -87
  324. package/build/utils/interactivity/utils.js.map +0 -1
  325. package/build/utils/interactivity/vdom.js +0 -119
  326. package/build/utils/interactivity/vdom.js.map +0 -1
  327. package/build-module/file/interactivity.js +0 -15
  328. package/build-module/file/interactivity.js.map +0 -1
  329. package/build-module/heading/heading-level-icon.js +0 -53
  330. package/build-module/heading/heading-level-icon.js.map +0 -1
  331. package/build-module/image/interactivity.js.map +0 -1
  332. package/build-module/navigation/interactivity.js +0 -164
  333. package/build-module/navigation/interactivity.js.map +0 -1
  334. package/build-module/navigation/view-modal.js +0 -58
  335. package/build-module/navigation/view-modal.js.map +0 -1
  336. package/build-module/utils/interactivity/constants.js +0 -2
  337. package/build-module/utils/interactivity/constants.js.map +0 -1
  338. package/build-module/utils/interactivity/directives.js +0 -209
  339. package/build-module/utils/interactivity/directives.js.map +0 -1
  340. package/build-module/utils/interactivity/hooks.js +0 -145
  341. package/build-module/utils/interactivity/hooks.js.map +0 -1
  342. package/build-module/utils/interactivity/hydration.js +0 -21
  343. package/build-module/utils/interactivity/hydration.js.map +0 -1
  344. package/build-module/utils/interactivity/index.js +0 -15
  345. package/build-module/utils/interactivity/index.js.map +0 -1
  346. package/build-module/utils/interactivity/portals.js +0 -100
  347. package/build-module/utils/interactivity/portals.js.map +0 -1
  348. package/build-module/utils/interactivity/store.js +0 -55
  349. package/build-module/utils/interactivity/store.js.map +0 -1
  350. package/build-module/utils/interactivity/utils.js +0 -75
  351. package/build-module/utils/interactivity/utils.js.map +0 -1
  352. package/build-module/utils/interactivity/vdom.js +0 -107
  353. package/build-module/utils/interactivity/vdom.js.map +0 -1
  354. package/src/file/interactivity.js +0 -15
  355. package/src/heading/heading-level-icon.js +0 -48
  356. package/src/navigation/interactivity.js +0 -169
  357. package/src/navigation/view-modal.js +0 -78
  358. package/src/utils/interactivity/constants.js +0 -1
  359. package/src/utils/interactivity/directives.js +0 -200
  360. package/src/utils/interactivity/hooks.js +0 -145
  361. package/src/utils/interactivity/hydration.js +0 -22
  362. package/src/utils/interactivity/index.js +0 -15
  363. package/src/utils/interactivity/portals.js +0 -98
  364. package/src/utils/interactivity/store.js +0 -45
  365. package/src/utils/interactivity/utils.js +0 -66
  366. package/src/utils/interactivity/vdom.js +0 -111
package/src/image/edit.js CHANGED
@@ -183,8 +183,6 @@ export function ImageEdit( {
183
183
  // Reset the dimension attributes if changing to a different image.
184
184
  if ( ! media.id || media.id !== id ) {
185
185
  additionalAttributes = {
186
- width: undefined,
187
- height: undefined,
188
186
  // Fallback to size "full" if there's no default image size.
189
187
  // It means the image is smaller, and the block will use a full-size URL.
190
188
  sizeSlug: hasDefaultSize( media, imageDefaultSize )
@@ -248,8 +246,6 @@ export function ImageEdit( {
248
246
  setAttributes( {
249
247
  url: newURL,
250
248
  id: undefined,
251
- width: undefined,
252
- height: undefined,
253
249
  sizeSlug: imageDefaultSize,
254
250
  } );
255
251
  }
@@ -4,13 +4,15 @@
4
4
  import { isBlobURL } from '@wordpress/blob';
5
5
  import {
6
6
  ExternalLink,
7
- PanelBody,
8
7
  ResizableBox,
9
8
  Spinner,
10
9
  TextareaControl,
11
10
  TextControl,
12
11
  ToolbarButton,
13
12
  ToolbarGroup,
13
+ __experimentalToolsPanel as ToolsPanel,
14
+ __experimentalToolsPanelItem as ToolsPanelItem,
15
+ __experimentalUseCustomUnits as useCustomUnits,
14
16
  } from '@wordpress/components';
15
17
  import { useViewportMatch, usePrevious } from '@wordpress/compose';
16
18
  import { useSelect, useDispatch } from '@wordpress/data';
@@ -18,7 +20,6 @@ import {
18
20
  BlockControls,
19
21
  InspectorControls,
20
22
  RichText,
21
- __experimentalImageSizeControl as ImageSizeControl,
22
23
  __experimentalImageURLInputUI as ImageURLInputUI,
23
24
  MediaReplaceFlow,
24
25
  store as blockEditorStore,
@@ -26,6 +27,7 @@ import {
26
27
  __experimentalImageEditor as ImageEditor,
27
28
  __experimentalGetElementClassName,
28
29
  __experimentalUseBorderProps as useBorderProps,
30
+ privateApis as blockEditorPrivateApis,
29
31
  } from '@wordpress/block-editor';
30
32
  import {
31
33
  useEffect,
@@ -34,7 +36,7 @@ import {
34
36
  useRef,
35
37
  useCallback,
36
38
  } from '@wordpress/element';
37
- import { __, sprintf, isRTL } from '@wordpress/i18n';
39
+ import { __, _x, sprintf, isRTL } from '@wordpress/i18n';
38
40
  import { getFilename } from '@wordpress/url';
39
41
  import {
40
42
  createBlock,
@@ -53,6 +55,7 @@ import { store as coreStore } from '@wordpress/core-data';
53
55
  /**
54
56
  * Internal dependencies
55
57
  */
58
+ import { unlock } from '../lock-unlock';
56
59
  import { createUpgradedEmbedBlock } from '../embed/util';
57
60
  import useClientWidth from './use-client-width';
58
61
  import { isExternalImage } from './edit';
@@ -61,6 +64,22 @@ import { isExternalImage } from './edit';
61
64
  * Module constants
62
65
  */
63
66
  import { MIN_SIZE, ALLOWED_MEDIA_TYPES } from './constants';
67
+ import { evalAspectRatio } from './utils';
68
+
69
+ const { DimensionsTool, ResolutionTool } = unlock( blockEditorPrivateApis );
70
+
71
+ const scaleOptions = [
72
+ {
73
+ value: 'cover',
74
+ label: _x( 'Cover', 'Scale option for dimensions control' ),
75
+ help: __( 'Image covers the space evenly.' ),
76
+ },
77
+ {
78
+ value: 'contain',
79
+ label: _x( 'Contain', 'Scale option for dimensions control' ),
80
+ help: __( 'Image is contained without distortion.' ),
81
+ },
82
+ ];
64
83
 
65
84
  export default function Image( {
66
85
  temporaryURL,
@@ -90,6 +109,8 @@ export default function Image( {
90
109
  title,
91
110
  width,
92
111
  height,
112
+ aspectRatio,
113
+ scale,
93
114
  linkTarget,
94
115
  sizeSlug,
95
116
  } = attributes;
@@ -272,8 +293,6 @@ export default function Image( {
272
293
 
273
294
  setAttributes( {
274
295
  url: newUrl,
275
- width: undefined,
276
- height: undefined,
277
296
  sizeSlug: newSizeSlug,
278
297
  } );
279
298
  }
@@ -329,6 +348,13 @@ export default function Image( {
329
348
  );
330
349
  }
331
350
 
351
+ // TODO: Can allow more units after figuring out how they should interact
352
+ // with the ResizableBox and ImageEditor components. Calculations later on
353
+ // for those components are currently assuming px units.
354
+ const dimensionsUnitsOptions = useCustomUnits( {
355
+ availableUnits: [ 'px' ],
356
+ } );
357
+
332
358
  const controls = (
333
359
  <>
334
360
  <BlockControls group="block">
@@ -407,41 +433,78 @@ export default function Image( {
407
433
  </BlockControls>
408
434
  ) }
409
435
  <InspectorControls>
410
- <PanelBody title={ __( 'Settings' ) }>
436
+ <ToolsPanel
437
+ label={ __( 'Settings' ) }
438
+ resetAll={ () =>
439
+ setAttributes( {
440
+ width: undefined,
441
+ height: undefined,
442
+ scale: undefined,
443
+ aspectRatio: undefined,
444
+ } )
445
+ }
446
+ >
411
447
  { ! multiImageSelection && (
412
- <TextareaControl
413
- __nextHasNoMarginBottom
448
+ <ToolsPanelItem
414
449
  label={ __( 'Alternative text' ) }
415
- value={ alt }
416
- onChange={ updateAlt }
417
- help={
418
- <>
419
- <ExternalLink href="https://www.w3.org/WAI/tutorials/images/decision-tree">
420
- { __(
421
- 'Describe the purpose of the image.'
422
- ) }
423
- </ExternalLink>
424
- <br />
425
- { __( 'Leave empty if decorative.' ) }
426
- </>
450
+ isShownByDefault={ true }
451
+ hasValue={ () => alt !== '' }
452
+ onDeselect={ () =>
453
+ setAttributes( { alt: undefined } )
427
454
  }
428
- />
455
+ >
456
+ <TextareaControl
457
+ label={ __( 'Alternative text' ) }
458
+ value={ alt }
459
+ onChange={ updateAlt }
460
+ help={
461
+ <>
462
+ <ExternalLink href="https://www.w3.org/WAI/tutorials/images/decision-tree">
463
+ { __(
464
+ 'Describe the purpose of the image.'
465
+ ) }
466
+ </ExternalLink>
467
+ <br />
468
+ { __( 'Leave empty if decorative.' ) }
469
+ </>
470
+ }
471
+ __nextHasNoMarginBottom
472
+ />
473
+ </ToolsPanelItem>
429
474
  ) }
430
- <ImageSizeControl
431
- onChangeImage={ updateImage }
432
- onChange={ ( value ) => setAttributes( value ) }
433
- slug={ sizeSlug }
434
- width={ width }
435
- height={ height }
436
- imageSizeOptions={ imageSizeOptions }
437
- isResizable={ isResizable }
438
- imageWidth={ naturalWidth }
439
- imageHeight={ naturalHeight }
440
- imageSizeHelp={ __(
441
- 'Select the size of the source image.'
442
- ) }
475
+ <DimensionsTool
476
+ value={ {
477
+ width: width && `${ width }px`,
478
+ height: height && `${ height }px`,
479
+ scale,
480
+ aspectRatio,
481
+ } }
482
+ onChange={ ( newValue ) => {
483
+ // Rebuilding the object forces setting `undefined`
484
+ // for values that are removed since setAttributes
485
+ // doesn't do anything with keys that aren't set.
486
+ setAttributes( {
487
+ width:
488
+ newValue.width &&
489
+ parseInt( newValue.width, 10 ),
490
+ height:
491
+ newValue.height &&
492
+ parseInt( newValue.height, 10 ),
493
+ scale: newValue.scale,
494
+ aspectRatio: newValue.aspectRatio,
495
+ } );
496
+ } }
497
+ defaultScale="cover"
498
+ defaultAspectRatio="auto"
499
+ scaleOptions={ scaleOptions }
500
+ unitsOptions={ dimensionsUnitsOptions }
501
+ />
502
+ <ResolutionTool
503
+ value={ sizeSlug }
504
+ onChange={ updateImage }
505
+ options={ imageSizeOptions }
443
506
  />
444
- </PanelBody>
507
+ </ToolsPanel>
445
508
  </InspectorControls>
446
509
  <InspectorControls group="advanced">
447
510
  <TextControl
@@ -483,9 +546,6 @@ export default function Image( {
483
546
 
484
547
  const borderProps = useBorderProps( attributes );
485
548
  const isRounded = attributes.className?.includes( 'is-style-rounded' );
486
- const hasCustomBorder =
487
- !! borderProps.className ||
488
- ( borderProps.style && Object.keys( borderProps.style ).length > 0 );
489
549
 
490
550
  let img = (
491
551
  // Disable reason: Image itself is not meant to be interactive, but
@@ -504,25 +564,20 @@ export default function Image( {
504
564
  } }
505
565
  ref={ imageRef }
506
566
  className={ borderProps.className }
507
- style={ borderProps.style }
567
+ style={ {
568
+ width:
569
+ ( width && height ) || aspectRatio ? '100%' : 'inherit',
570
+ height:
571
+ ( width && height ) || aspectRatio ? '100%' : 'inherit',
572
+ objectFit: scale,
573
+ ...borderProps.style,
574
+ } }
508
575
  />
509
576
  { temporaryURL && <Spinner /> }
510
577
  </>
511
578
  /* eslint-enable jsx-a11y/no-noninteractive-element-interactions, jsx-a11y/click-events-have-key-events */
512
579
  );
513
580
 
514
- let imageWidthWithinContainer;
515
- let imageHeightWithinContainer;
516
-
517
- if ( clientWidth && naturalWidth && naturalHeight ) {
518
- const exceedMaxWidth = naturalWidth > clientWidth;
519
- const ratio = naturalHeight / naturalWidth;
520
- imageWidthWithinContainer = exceedMaxWidth ? clientWidth : naturalWidth;
521
- imageHeightWithinContainer = exceedMaxWidth
522
- ? clientWidth * ratio
523
- : naturalHeight;
524
- }
525
-
526
581
  // clientWidth needs to be a number for the image Cropper to work, but sometimes it's 0
527
582
  // So we try using the imageRef width first and fallback to clientWidth.
528
583
  const fallbackClientWidth = imageRef.current?.width || clientWidth;
@@ -546,13 +601,18 @@ export default function Image( {
546
601
  borderProps={ isRounded ? undefined : borderProps }
547
602
  />
548
603
  );
549
- } else if ( ! isResizable || ! imageWidthWithinContainer ) {
550
- img = <div style={ { width, height } }>{ img }</div>;
604
+ } else if ( ! isResizable ) {
605
+ img = <div style={ { width, height, aspectRatio } }>{ img }</div>;
551
606
  } else {
552
- const currentWidth = width || imageWidthWithinContainer;
553
- const currentHeight = height || imageHeightWithinContainer;
607
+ const ratio =
608
+ ( aspectRatio && evalAspectRatio( aspectRatio ) ) ||
609
+ ( width && height && width / height ) ||
610
+ naturalWidth / naturalHeight ||
611
+ 1;
612
+
613
+ const currentWidth = ! width && height ? height * ratio : width;
614
+ const currentHeight = ! height && width ? width / ratio : height;
554
615
 
555
- const ratio = naturalWidth / naturalHeight;
556
616
  const minWidth =
557
617
  naturalWidth < naturalHeight ? MIN_SIZE : MIN_SIZE * ratio;
558
618
  const minHeight =
@@ -600,16 +660,24 @@ export default function Image( {
600
660
 
601
661
  img = (
602
662
  <ResizableBox
663
+ style={ {
664
+ display: 'block',
665
+ objectFit: scale,
666
+ aspectRatio:
667
+ ! width && ! height && aspectRatio
668
+ ? aspectRatio
669
+ : undefined,
670
+ } }
603
671
  size={ {
604
- width: width ?? 'auto',
605
- height: height && ! hasCustomBorder ? height : 'auto',
672
+ width: currentWidth ?? 'auto',
673
+ height: currentHeight ?? 'auto',
606
674
  } }
607
675
  showHandle={ isSelected }
608
676
  minWidth={ minWidth }
609
677
  maxWidth={ maxWidthBuffer }
610
678
  minHeight={ minHeight }
611
679
  maxHeight={ maxWidthBuffer / ratio }
612
- lockAspectRatio
680
+ lockAspectRatio={ ratio }
613
681
  enable={ {
614
682
  top: false,
615
683
  right: showRightHandle,
@@ -617,11 +685,12 @@ export default function Image( {
617
685
  left: showLeftHandle,
618
686
  } }
619
687
  onResizeStart={ onResizeStart }
620
- onResizeStop={ ( event, direction, elt, delta ) => {
688
+ onResizeStop={ ( event, direction, elt ) => {
621
689
  onResizeStop();
622
690
  setAttributes( {
623
- width: parseInt( currentWidth + delta.width, 10 ),
624
- height: parseInt( currentHeight + delta.height, 10 ),
691
+ width: elt.offsetWidth,
692
+ height: elt.offsetHeight,
693
+ aspectRatio: undefined,
625
694
  } );
626
695
  } }
627
696
  resizeRatio={ align === 'center' ? 2 : 1 }
package/src/image/save.js CHANGED
@@ -24,6 +24,8 @@ export default function save( { attributes } ) {
24
24
  linkClass,
25
25
  width,
26
26
  height,
27
+ aspectRatio,
28
+ scale,
27
29
  id,
28
30
  linkTarget,
29
31
  sizeSlug,
@@ -52,7 +54,13 @@ export default function save( { attributes } ) {
52
54
  src={ url }
53
55
  alt={ alt }
54
56
  className={ imageClasses || undefined }
55
- style={ borderProps.style }
57
+ style={ {
58
+ ...borderProps.style,
59
+ aspectRatio,
60
+ objectFit: scale,
61
+ width,
62
+ height,
63
+ } }
56
64
  width={ width }
57
65
  height={ height }
58
66
  title={ title }
@@ -184,11 +184,12 @@
184
184
  width: 100vw;
185
185
  height: 100vh;
186
186
  visibility: hidden;
187
+ cursor: zoom-out;
187
188
 
188
189
  .close-button {
189
190
  position: absolute;
190
- top: 12.5px;
191
- right: 12.5px;
191
+ top: calc(env(safe-area-inset-top) + 12.5px);
192
+ right: calc(env(safe-area-inset-right) + 12.5px);
192
193
  padding: 0;
193
194
  cursor: pointer;
194
195
  z-index: 5000000;
@@ -231,6 +232,18 @@
231
232
  }
232
233
 
233
234
  &.fade {
235
+ .wp-block-image {
236
+ padding: 40px 0;
237
+
238
+ @media screen and (min-width: 480px) {
239
+ padding: 40px;
240
+ }
241
+
242
+ @media screen and (min-width: 1920px) {
243
+ padding: 40px 80px;
244
+ }
245
+ }
246
+
234
247
  &.active {
235
248
  visibility: visible;
236
249
  animation: both turn-on-visibility 0.25s;
@@ -3,6 +3,22 @@
3
3
  */
4
4
  import { NEW_TAB_REL } from './constants';
5
5
 
6
+ /**
7
+ * Evaluates a CSS aspect-ratio property value as a number.
8
+ *
9
+ * Degenerate or invalid ratios behave as 'auto'. And 'auto' ratios return NaN.
10
+ *
11
+ * @see https://drafts.csswg.org/css-sizing-4/#aspect-ratio
12
+ *
13
+ * @param {string} value CSS aspect-ratio property value.
14
+ * @return {number} Numerical aspect ratio or NaN if invalid.
15
+ */
16
+ export function evalAspectRatio( value ) {
17
+ const [ width, height = 1 ] = value.split( '/' ).map( Number );
18
+ const aspectRatio = width / height;
19
+ return aspectRatio === Infinity || aspectRatio === 0 ? NaN : aspectRatio;
20
+ }
21
+
6
22
  export function removeNewTabRel( currentRel ) {
7
23
  let newRel = currentRel;
8
24
 
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Internal dependencies
2
+ * WordPress dependencies
3
3
  */
4
- import { store } from '../utils/interactivity';
4
+ import { store } from '@wordpress/interactivity';
5
5
 
6
6
  const focusableSelectors = [
7
7
  'a[href]',
@@ -22,32 +22,43 @@ store( {
22
22
  core: {
23
23
  image: {
24
24
  showLightbox: ( { context, event } ) => {
25
+ // We can't initialize the lightbox until the reference
26
+ // image is loaded, otherwise the UX is broken.
27
+ if ( ! context.core.image.imageLoaded ) {
28
+ return;
29
+ }
25
30
  context.core.image.initialized = true;
26
31
  context.core.image.lastFocusedElement =
27
32
  window.document.activeElement;
28
33
  context.core.image.scrollDelta = 0;
29
34
 
35
+ context.core.image.lightboxEnabled = true;
36
+ if ( context.core.image.lightboxAnimation === 'zoom' ) {
37
+ setZoomStyles(
38
+ event.target.nextElementSibling,
39
+ context,
40
+ event
41
+ );
42
+ }
43
+ // Hide overflow only when the animation is in progress,
44
+ // otherwise the removal of the scrollbars will draw attention
45
+ // to itself and look like an error
46
+ document.documentElement.classList.add(
47
+ 'has-lightbox-open'
48
+ );
49
+
30
50
  // Since the img is hidden and its src not loaded until
31
51
  // the lightbox is opened, let's create an img element on the fly
32
52
  // so we can get the dimensions we need to calculate the styles
53
+ context.core.image.preloadInitialized = true;
33
54
  const imgDom = document.createElement( 'img' );
34
-
35
55
  imgDom.onload = function () {
36
- // Enable the lightbox only after the image
37
- // is loaded to prevent flashing of unstyled content
38
- context.core.image.lightboxEnabled = true;
39
- if ( context.core.image.lightboxAnimation === 'zoom' ) {
40
- setZoomStyles( imgDom, context, event );
41
- }
42
-
43
- // Hide overflow only when the animation is in progress,
44
- // otherwise the removal of the scrollbars will draw attention
45
- // to itself and look like an error
46
- document.documentElement.classList.add(
47
- 'has-lightbox-open'
48
- );
56
+ context.core.image.activateLargeImage = true;
49
57
  };
50
- imgDom.setAttribute( 'src', context.core.image.imageSrc );
58
+ imgDom.setAttribute(
59
+ 'src',
60
+ context.core.image.imageUploadedSrc
61
+ );
51
62
  },
52
63
  hideLightbox: async ( { context, event } ) => {
53
64
  context.core.image.hideAnimationEnabled = true;
@@ -122,6 +133,16 @@ store( {
122
133
  }
123
134
  }
124
135
  },
136
+ preloadLightboxImage: ( { context } ) => {
137
+ if ( ! context.core.image.preloadInitialized ) {
138
+ context.core.image.preloadInitialized = true;
139
+ const imgDom = document.createElement( 'img' );
140
+ imgDom.setAttribute(
141
+ 'src',
142
+ context.core.image.imageUploadedSrc
143
+ );
144
+ }
145
+ },
125
146
  },
126
147
  },
127
148
  },
@@ -131,9 +152,15 @@ store( {
131
152
  roleAttribute: ( { context } ) => {
132
153
  return context.core.image.lightboxEnabled ? 'dialog' : '';
133
154
  },
134
- imageSrc: ( { context } ) => {
155
+ responsiveImgSrc: ( { context } ) => {
156
+ return context.core.image.activateLargeImage &&
157
+ context.core.image.hideAnimationEnabled
158
+ ? ''
159
+ : context.core.image.imageCurrentSrc;
160
+ },
161
+ enlargedImgSrc: ( { context } ) => {
135
162
  return context.core.image.initialized
136
- ? context.core.image.imageSrc
163
+ ? context.core.image.imageUploadedSrc
137
164
  : '';
138
165
  },
139
166
  },
@@ -142,6 +169,18 @@ store( {
142
169
  effects: {
143
170
  core: {
144
171
  image: {
172
+ setCurrentSrc: ( { context, ref } ) => {
173
+ if ( ref.complete ) {
174
+ context.core.image.imageLoaded = true;
175
+ context.core.image.imageCurrentSrc = ref.currentSrc;
176
+ } else {
177
+ ref.addEventListener( 'load', function () {
178
+ context.core.image.imageLoaded = true;
179
+ context.core.image.imageCurrentSrc =
180
+ this.currentSrc;
181
+ } );
182
+ }
183
+ },
145
184
  initLightbox: async ( { context, ref } ) => {
146
185
  context.core.image.figureRef =
147
186
  ref.querySelector( 'figure' );
@@ -163,51 +202,61 @@ store( {
163
202
  } );
164
203
 
165
204
  function setZoomStyles( imgDom, context, event ) {
166
- let targetWidth = imgDom.naturalWidth;
167
- let targetHeight = imgDom.naturalHeight;
205
+ // Typically, we use the image's full-sized dimensions. If those
206
+ // dimensions have not been set (i.e. an external image with only one size),
207
+ // the image's dimensions in the lightbox are the same
208
+ // as those of the image in the content.
209
+ let targetWidth =
210
+ context.core.image.targetWidth !== 'none'
211
+ ? context.core.image.targetWidth
212
+ : event.target.nextElementSibling.naturalWidth;
213
+ let targetHeight =
214
+ context.core.image.targetHeight !== 'none'
215
+ ? context.core.image.targetHeight
216
+ : event.target.nextElementSibling.naturalHeight;
168
217
 
169
- const verticalPadding = 40;
218
+ // Since the lightbox image has `position:absolute`, it
219
+ // ignores its parent's padding, so we need to set padding here
220
+ // to calculate dimensions and positioning.
170
221
 
171
- // As per the design, let's allow the image to stretch
172
- // to the full width of its containing figure, but for the height,
173
- // constrain it with a fixed padding
174
- const containerWidth = context.core.image.figureRef.clientWidth;
222
+ // As per the design, let's constrain the height with fixed padding
223
+ const containerOuterHeight = window.innerHeight;
224
+ const verticalPadding = 40;
225
+ const containerInnerHeight = containerOuterHeight - verticalPadding * 2;
175
226
 
176
- // The lightbox image has `positione:absolute` and
177
- // ignores its parent's padding, so let's set the padding here,
178
- // to be used when calculating the image width and positioning
227
+ // Let's set a variable horizontal padding based on the container width
228
+ const containerOuterWidth = window.innerWidth;
179
229
  let horizontalPadding = 0;
180
- if ( containerWidth > 480 ) {
230
+ if ( containerOuterWidth > 480 ) {
181
231
  horizontalPadding = 40;
182
- } else if ( containerWidth > 1920 ) {
232
+ } else if ( containerOuterWidth > 1920 ) {
183
233
  horizontalPadding = 80;
184
234
  }
185
-
186
- const containerHeight =
187
- context.core.image.figureRef.clientHeight - verticalPadding * 2;
235
+ const containerInnerWidth = containerOuterWidth - horizontalPadding * 2;
188
236
 
189
237
  // Check difference between the image and figure dimensions
190
238
  const widthOverflow = Math.abs(
191
- Math.min( containerWidth - targetWidth, 0 )
239
+ Math.min( containerInnerWidth - targetWidth, 0 )
192
240
  );
193
241
  const heightOverflow = Math.abs(
194
- Math.min( containerHeight - targetHeight, 0 )
242
+ Math.min( containerInnerHeight - targetHeight, 0 )
195
243
  );
196
244
 
197
- // If image is larger than its container any dimension, resize along its largest axis.
198
- // For vertically oriented devices, always maximize the width.
245
+ // If the image is larger than the container, let's resize
246
+ // it along the greater axis relative to the container
199
247
  if ( widthOverflow > 0 || heightOverflow > 0 ) {
200
- if (
201
- widthOverflow >= heightOverflow ||
202
- containerHeight >= containerWidth
203
- ) {
204
- targetWidth = containerWidth - horizontalPadding * 2;
248
+ const containerInnerAspectRatio =
249
+ containerInnerWidth / containerInnerHeight;
250
+ const imageAspectRatio = targetWidth / targetHeight;
251
+
252
+ if ( imageAspectRatio > containerInnerAspectRatio ) {
253
+ targetWidth = containerInnerWidth;
205
254
  targetHeight =
206
- imgDom.naturalHeight * ( targetWidth / imgDom.naturalWidth );
255
+ ( targetWidth * imgDom.naturalHeight ) / imgDom.naturalWidth;
207
256
  } else {
208
- targetHeight = containerHeight;
257
+ targetHeight = containerInnerHeight;
209
258
  targetWidth =
210
- imgDom.naturalWidth * ( targetHeight / imgDom.naturalHeight );
259
+ ( targetHeight * imgDom.naturalWidth ) / imgDom.naturalHeight;
211
260
  }
212
261
  }
213
262
 
@@ -221,16 +270,16 @@ function setZoomStyles( imgDom, context, event ) {
221
270
 
222
271
  // Get values used to center the image
223
272
  let targetLeft = 0;
224
- if ( targetWidth >= containerWidth ) {
273
+ if ( targetWidth >= containerInnerWidth ) {
225
274
  targetLeft = horizontalPadding;
226
275
  } else {
227
- targetLeft = ( containerWidth - targetWidth ) / 2;
276
+ targetLeft = ( containerOuterWidth - targetWidth ) / 2;
228
277
  }
229
278
  let targetTop = 0;
230
- if ( targetHeight >= containerHeight ) {
279
+ if ( targetHeight >= containerInnerHeight ) {
231
280
  targetTop = verticalPadding;
232
281
  } else {
233
- targetTop = ( containerHeight - targetHeight ) / 2 + verticalPadding;
282
+ targetTop = ( containerOuterHeight - targetHeight ) / 2;
234
283
  }
235
284
 
236
285
  const root = document.documentElement;
package/src/index.js CHANGED
@@ -142,7 +142,6 @@ const getAllBlocks = () => {
142
142
  buttons,
143
143
  calendar,
144
144
  categories,
145
- ...( window.wp && window.wp.oldEditor ? [ classic ] : [] ), // Only add the classic block in WP Context.
146
145
  code,
147
146
  column,
148
147
  columns,
@@ -229,6 +228,24 @@ const getAllBlocks = () => {
229
228
  queryTitle,
230
229
  postAuthorBiography,
231
230
  ];
231
+
232
+ // When in a WordPress context, conditionally
233
+ // add the classic block and TinyMCE editor
234
+ // under any of the following conditions:
235
+ // - the current post contains a classic block
236
+ // - the experiment to disable TinyMCE isn't active.
237
+ // - a query argument specifies that TinyMCE should be loaded
238
+ if (
239
+ window?.wp?.oldEditor &&
240
+ ( window?.wp?.needsClassicBlock ||
241
+ ! window?.__experimentalDisableTinymce ||
242
+ !! new URLSearchParams( window?.location?.search ).get(
243
+ 'requiresTinymce'
244
+ ) )
245
+ ) {
246
+ blocks.push( classic );
247
+ }
248
+
232
249
  return blocks.filter( Boolean );
233
250
  };
234
251