@wordpress/block-library 11.1.0 → 11.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (444) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/build/accordion-heading/block.json +1 -0
  3. package/build/archives/block.json +3 -0
  4. package/build/audio/edit.cjs +2 -1
  5. package/build/audio/edit.cjs.map +2 -2
  6. package/build/avatar/block.json +4 -0
  7. package/build/avatar/edit.cjs +31 -1
  8. package/build/avatar/edit.cjs.map +3 -3
  9. package/build/button/block.json +6 -0
  10. package/build/button/edit.cjs +9 -6
  11. package/build/button/edit.cjs.map +2 -2
  12. package/build/buttons/block.json +6 -1
  13. package/build/code/block.json +4 -0
  14. package/build/column/edit.cjs +5 -0
  15. package/build/column/edit.cjs.map +2 -2
  16. package/build/columns/block.json +4 -0
  17. package/build/columns/edit.cjs +21 -112
  18. package/build/columns/edit.cjs.map +3 -3
  19. package/build/comments/edit/placeholder.cjs +95 -87
  20. package/build/comments/edit/placeholder.cjs.map +2 -2
  21. package/build/comments-pagination/block.json +11 -0
  22. package/build/cover/block.json +2 -1
  23. package/build/cover/edit/index.cjs +26 -5
  24. package/build/cover/edit/index.cjs.map +2 -2
  25. package/build/cover/edit/inspector-controls.cjs +4 -1
  26. package/build/cover/edit/inspector-controls.cjs.map +2 -2
  27. package/build/cover/embed-video-utils.cjs +9 -8
  28. package/build/cover/embed-video-utils.cjs.map +2 -2
  29. package/build/cover/view.cjs +21 -0
  30. package/build/cover/view.cjs.map +7 -0
  31. package/build/details/block.json +3 -0
  32. package/build/embed/block.json +6 -1
  33. package/build/file/block.json +5 -0
  34. package/build/footnotes/block.json +4 -0
  35. package/build/gallery/block.json +13 -0
  36. package/build/gallery/dynamic-gallery.cjs +32 -93
  37. package/build/gallery/dynamic-gallery.cjs.map +3 -3
  38. package/build/gallery/edit.cjs +103 -40
  39. package/build/gallery/edit.cjs.map +2 -2
  40. package/build/gallery/order-controls.cjs +107 -0
  41. package/build/gallery/order-controls.cjs.map +7 -0
  42. package/build/gallery/order-images.cjs +92 -0
  43. package/build/gallery/order-images.cjs.map +7 -0
  44. package/build/gallery/order-options.cjs +62 -0
  45. package/build/gallery/order-options.cjs.map +7 -0
  46. package/build/gallery/use-dynamic-gallery.cjs +1 -7
  47. package/build/gallery/use-dynamic-gallery.cjs.map +2 -2
  48. package/build/gallery/use-get-media.cjs +2 -3
  49. package/build/gallery/use-get-media.cjs.map +2 -2
  50. package/build/group/edit.cjs +3 -3
  51. package/build/group/edit.cjs.map +2 -2
  52. package/build/heading/block.json +5 -0
  53. package/build/home-link/block.json +12 -0
  54. package/build/icon/components/custom-inserter/index.cjs +3 -1
  55. package/build/icon/components/custom-inserter/index.cjs.map +2 -2
  56. package/build/icon/edit.cjs +49 -5
  57. package/build/icon/edit.cjs.map +2 -2
  58. package/build/image/use-open-image-media-editor-modal.cjs +32 -28
  59. package/build/image/use-open-image-media-editor-modal.cjs.map +2 -2
  60. package/build/image/view.cjs +44 -50
  61. package/build/image/view.cjs.map +2 -2
  62. package/build/latest-comments/block.json +10 -0
  63. package/build/latest-posts/block.json +4 -0
  64. package/build/list/block.json +12 -1
  65. package/build/list-item/block.json +8 -1
  66. package/build/list-item/index.cjs +4 -0
  67. package/build/list-item/index.cjs.map +3 -3
  68. package/build/loginout/block.json +4 -0
  69. package/build/math/block.json +4 -0
  70. package/build/media-text/block.json +18 -0
  71. package/build/navigation-link/link-ui/index.cjs +33 -19
  72. package/build/navigation-link/link-ui/index.cjs.map +2 -2
  73. package/build/navigation-link/shared/index.cjs +5 -0
  74. package/build/navigation-link/shared/index.cjs.map +2 -2
  75. package/build/navigation-link/shared/use-block-suggestions.cjs +141 -0
  76. package/build/navigation-link/shared/use-block-suggestions.cjs.map +7 -0
  77. package/build/page-list/block.json +4 -0
  78. package/build/paragraph/block.json +1 -0
  79. package/build/post-author-biography/block.json +1 -0
  80. package/build/post-comments-form/block.json +5 -0
  81. package/build/post-content/block.json +2 -1
  82. package/build/post-excerpt/block.json +4 -0
  83. package/build/post-featured-image/block.json +1 -0
  84. package/build/post-featured-image/edit.cjs +1 -1
  85. package/build/post-featured-image/edit.cjs.map +2 -2
  86. package/build/post-terms/block.json +4 -0
  87. package/build/post-time-to-read/block.json +4 -0
  88. package/build/post-title/block.json +4 -0
  89. package/build/preformatted/block.json +4 -0
  90. package/build/pullquote/block.json +2 -1
  91. package/build/query-no-results/block.json +4 -0
  92. package/build/query-pagination/block.json +17 -0
  93. package/build/query-total/block.json +4 -0
  94. package/build/quote/block.json +2 -0
  95. package/build/read-more/block.json +5 -0
  96. package/build/rss/block.json +4 -0
  97. package/build/search/block.json +2 -1
  98. package/build/site-tagline/block.json +4 -0
  99. package/build/site-title/block.json +4 -0
  100. package/build/social-links/block.json +1 -0
  101. package/build/tab-list/block.json +4 -0
  102. package/build/tab-list/edit.cjs +3 -1
  103. package/build/tab-list/edit.cjs.map +3 -3
  104. package/build/tab-list/save.cjs +3 -1
  105. package/build/tab-list/save.cjs.map +3 -3
  106. package/build/tab-panels/block.json +3 -0
  107. package/build/tabs/block.json +3 -0
  108. package/build/term-count/block.json +5 -0
  109. package/build/term-description/block.json +4 -0
  110. package/build/term-name/block.json +6 -1
  111. package/build/term-template/block.json +4 -0
  112. package/build/utils/waveform-utils.cjs +2 -2
  113. package/build/utils/waveform-utils.cjs.map +2 -2
  114. package/build/verse/block.json +4 -0
  115. package/build/video/block.json +7 -1
  116. package/build/video/edit.cjs +10 -2
  117. package/build/video/edit.cjs.map +2 -2
  118. package/build-module/accordion-heading/block.json +1 -0
  119. package/build-module/archives/block.json +3 -0
  120. package/build-module/audio/edit.mjs +2 -1
  121. package/build-module/audio/edit.mjs.map +2 -2
  122. package/build-module/avatar/block.json +4 -0
  123. package/build-module/avatar/edit.mjs +33 -2
  124. package/build-module/avatar/edit.mjs.map +2 -2
  125. package/build-module/button/block.json +6 -0
  126. package/build-module/button/edit.mjs +11 -7
  127. package/build-module/button/edit.mjs.map +2 -2
  128. package/build-module/buttons/block.json +6 -1
  129. package/build-module/code/block.json +4 -0
  130. package/build-module/column/edit.mjs +5 -0
  131. package/build-module/column/edit.mjs.map +2 -2
  132. package/build-module/columns/block.json +4 -0
  133. package/build-module/columns/edit.mjs +22 -122
  134. package/build-module/columns/edit.mjs.map +2 -2
  135. package/build-module/comments/edit/placeholder.mjs +95 -87
  136. package/build-module/comments/edit/placeholder.mjs.map +2 -2
  137. package/build-module/comments-pagination/block.json +11 -0
  138. package/build-module/cover/block.json +2 -1
  139. package/build-module/cover/edit/index.mjs +32 -6
  140. package/build-module/cover/edit/index.mjs.map +2 -2
  141. package/build-module/cover/edit/inspector-controls.mjs +5 -2
  142. package/build-module/cover/edit/inspector-controls.mjs.map +2 -2
  143. package/build-module/cover/embed-video-utils.mjs +9 -8
  144. package/build-module/cover/embed-video-utils.mjs.map +2 -2
  145. package/build-module/cover/view.mjs +19 -0
  146. package/build-module/cover/view.mjs.map +7 -0
  147. package/build-module/details/block.json +3 -0
  148. package/build-module/embed/block.json +6 -1
  149. package/build-module/file/block.json +5 -0
  150. package/build-module/footnotes/block.json +4 -0
  151. package/build-module/gallery/block.json +13 -0
  152. package/build-module/gallery/dynamic-gallery.mjs +33 -97
  153. package/build-module/gallery/dynamic-gallery.mjs.map +2 -2
  154. package/build-module/gallery/edit.mjs +110 -42
  155. package/build-module/gallery/edit.mjs.map +2 -2
  156. package/build-module/gallery/order-controls.mjs +87 -0
  157. package/build-module/gallery/order-controls.mjs.map +7 -0
  158. package/build-module/gallery/order-images.mjs +66 -0
  159. package/build-module/gallery/order-images.mjs.map +7 -0
  160. package/build-module/gallery/order-options.mjs +33 -0
  161. package/build-module/gallery/order-options.mjs.map +7 -0
  162. package/build-module/gallery/use-dynamic-gallery.mjs +1 -7
  163. package/build-module/gallery/use-dynamic-gallery.mjs.map +2 -2
  164. package/build-module/gallery/use-get-media.mjs +2 -3
  165. package/build-module/gallery/use-get-media.mjs.map +2 -2
  166. package/build-module/group/edit.mjs +4 -4
  167. package/build-module/group/edit.mjs.map +2 -2
  168. package/build-module/heading/block.json +5 -0
  169. package/build-module/home-link/block.json +12 -0
  170. package/build-module/icon/components/custom-inserter/index.mjs +3 -1
  171. package/build-module/icon/components/custom-inserter/index.mjs.map +2 -2
  172. package/build-module/icon/edit.mjs +50 -6
  173. package/build-module/icon/edit.mjs.map +2 -2
  174. package/build-module/image/use-open-image-media-editor-modal.mjs +32 -28
  175. package/build-module/image/use-open-image-media-editor-modal.mjs.map +2 -2
  176. package/build-module/image/view.mjs +44 -50
  177. package/build-module/image/view.mjs.map +2 -2
  178. package/build-module/latest-comments/block.json +10 -0
  179. package/build-module/latest-posts/block.json +4 -0
  180. package/build-module/list/block.json +12 -1
  181. package/build-module/list-item/block.json +8 -1
  182. package/build-module/list-item/index.mjs +4 -0
  183. package/build-module/list-item/index.mjs.map +2 -2
  184. package/build-module/loginout/block.json +4 -0
  185. package/build-module/math/block.json +4 -0
  186. package/build-module/media-text/block.json +18 -0
  187. package/build-module/navigation-link/link-ui/index.mjs +39 -20
  188. package/build-module/navigation-link/link-ui/index.mjs.map +2 -2
  189. package/build-module/navigation-link/shared/index.mjs +6 -0
  190. package/build-module/navigation-link/shared/index.mjs.map +2 -2
  191. package/build-module/navigation-link/shared/use-block-suggestions.mjs +120 -0
  192. package/build-module/navigation-link/shared/use-block-suggestions.mjs.map +7 -0
  193. package/build-module/page-list/block.json +4 -0
  194. package/build-module/paragraph/block.json +1 -0
  195. package/build-module/post-author-biography/block.json +1 -0
  196. package/build-module/post-comments-form/block.json +5 -0
  197. package/build-module/post-content/block.json +2 -1
  198. package/build-module/post-excerpt/block.json +4 -0
  199. package/build-module/post-featured-image/block.json +1 -0
  200. package/build-module/post-featured-image/edit.mjs +1 -1
  201. package/build-module/post-featured-image/edit.mjs.map +2 -2
  202. package/build-module/post-terms/block.json +4 -0
  203. package/build-module/post-time-to-read/block.json +4 -0
  204. package/build-module/post-title/block.json +4 -0
  205. package/build-module/preformatted/block.json +4 -0
  206. package/build-module/pullquote/block.json +2 -1
  207. package/build-module/query-no-results/block.json +4 -0
  208. package/build-module/query-pagination/block.json +17 -0
  209. package/build-module/query-total/block.json +4 -0
  210. package/build-module/quote/block.json +2 -0
  211. package/build-module/read-more/block.json +5 -0
  212. package/build-module/rss/block.json +4 -0
  213. package/build-module/search/block.json +2 -1
  214. package/build-module/site-tagline/block.json +4 -0
  215. package/build-module/site-title/block.json +4 -0
  216. package/build-module/social-links/block.json +1 -0
  217. package/build-module/tab-list/block.json +4 -0
  218. package/build-module/tab-list/edit.mjs +4 -1
  219. package/build-module/tab-list/edit.mjs.map +2 -2
  220. package/build-module/tab-list/save.mjs +4 -1
  221. package/build-module/tab-list/save.mjs.map +2 -2
  222. package/build-module/tab-panels/block.json +3 -0
  223. package/build-module/tabs/block.json +3 -0
  224. package/build-module/term-count/block.json +5 -0
  225. package/build-module/term-description/block.json +4 -0
  226. package/build-module/term-name/block.json +6 -1
  227. package/build-module/term-template/block.json +4 -0
  228. package/build-module/utils/waveform-utils.mjs +1 -1
  229. package/build-module/utils/waveform-utils.mjs.map +1 -1
  230. package/build-module/verse/block.json +4 -0
  231. package/build-module/video/block.json +7 -1
  232. package/build-module/video/edit.mjs +10 -2
  233. package/build-module/video/edit.mjs.map +2 -2
  234. package/build-style/avatar/editor-rtl.css +4 -0
  235. package/build-style/avatar/editor.css +4 -0
  236. package/build-style/comments-pagination/style-rtl.css +3 -0
  237. package/build-style/comments-pagination/style.css +3 -0
  238. package/build-style/common-rtl.css +32 -1
  239. package/build-style/common.css +35 -2
  240. package/build-style/editor-rtl.css +11 -4
  241. package/build-style/editor.css +11 -4
  242. package/build-style/embed/style-rtl.css +4 -1
  243. package/build-style/embed/style.css +4 -1
  244. package/build-style/gallery/editor-rtl.css +1 -3
  245. package/build-style/gallery/editor.css +1 -3
  246. package/build-style/image/style-rtl.css +11 -2
  247. package/build-style/image/style.css +11 -2
  248. package/build-style/media-text/style-rtl.css +4 -1
  249. package/build-style/media-text/style.css +4 -1
  250. package/build-style/query-pagination/style-rtl.css +3 -0
  251. package/build-style/query-pagination/style.css +3 -0
  252. package/build-style/style-rtl.css +70 -9
  253. package/build-style/style.css +73 -10
  254. package/build-style/table/editor-rtl.css +6 -1
  255. package/build-style/table/editor.css +6 -1
  256. package/build-style/table/style-rtl.css +4 -2
  257. package/build-style/table/style.css +4 -2
  258. package/build-style/tag-cloud/style-rtl.css +1 -1
  259. package/build-style/tag-cloud/style.css +1 -1
  260. package/build-style/verse/style-rtl.css +8 -1
  261. package/build-style/verse/style.css +8 -1
  262. package/build-types/gallery/order-controls.d.ts +58 -0
  263. package/build-types/gallery/order-controls.d.ts.map +1 -0
  264. package/build-types/gallery/order-options.d.ts +67 -0
  265. package/build-types/gallery/order-options.d.ts.map +1 -0
  266. package/package.json +44 -41
  267. package/src/accordion-heading/README.md +1 -0
  268. package/src/accordion-heading/block.json +1 -0
  269. package/src/archives/README.md +2 -0
  270. package/src/archives/block.json +3 -0
  271. package/src/audio/edit.jsx +2 -1
  272. package/src/avatar/README.md +2 -0
  273. package/src/avatar/block.json +4 -0
  274. package/src/avatar/edit.jsx +48 -2
  275. package/src/avatar/editor.scss +4 -0
  276. package/src/avatar/index.php +5 -3
  277. package/src/breadcrumbs/index.php +1 -1
  278. package/src/button/README.md +4 -0
  279. package/src/button/block.json +6 -0
  280. package/src/button/edit.jsx +47 -52
  281. package/src/button/index.php +47 -0
  282. package/src/buttons/README.md +4 -0
  283. package/src/buttons/block.json +6 -1
  284. package/src/code/README.md +3 -0
  285. package/src/code/block.json +4 -0
  286. package/src/column/edit.jsx +6 -0
  287. package/src/columns/README.md +3 -0
  288. package/src/columns/block.json +4 -0
  289. package/src/columns/edit.jsx +1 -131
  290. package/src/comments/edit/placeholder.jsx +5 -1
  291. package/src/comments-pagination/README.md +4 -0
  292. package/src/comments-pagination/block.json +11 -0
  293. package/src/comments-pagination/style.scss +3 -0
  294. package/src/common.scss +38 -0
  295. package/src/cover/README.md +1 -0
  296. package/src/cover/block.json +2 -1
  297. package/src/cover/edit/index.jsx +38 -6
  298. package/src/cover/edit/inspector-controls.jsx +10 -1
  299. package/src/cover/embed-video-utils.js +18 -10
  300. package/src/cover/index.php +44 -15
  301. package/src/cover/test/edit.browser.test.js +182 -2
  302. package/src/cover/test/embed-video-utils.test.js +48 -0
  303. package/src/cover/view.js +22 -0
  304. package/src/details/README.md +2 -0
  305. package/src/details/block.json +3 -0
  306. package/src/embed/README.md +4 -0
  307. package/src/embed/block.json +6 -1
  308. package/src/embed/style.scss +7 -1
  309. package/src/file/README.md +4 -0
  310. package/src/file/block.json +5 -0
  311. package/src/footnotes/README.md +3 -0
  312. package/src/footnotes/block.json +4 -0
  313. package/src/gallery/README.md +13 -0
  314. package/src/gallery/block.json +13 -0
  315. package/src/gallery/dynamic-gallery.jsx +11 -91
  316. package/src/gallery/edit.jsx +146 -47
  317. package/src/gallery/editor.scss +5 -9
  318. package/src/gallery/order-controls.tsx +143 -0
  319. package/src/gallery/order-images.js +111 -0
  320. package/src/gallery/order-options.ts +75 -0
  321. package/src/gallery/test/edit.jsdom.test.js +87 -10
  322. package/src/gallery/test/order-images.js +162 -0
  323. package/src/gallery/use-dynamic-gallery.js +1 -9
  324. package/src/gallery/use-get-media.js +7 -2
  325. package/src/group/edit.jsx +5 -5
  326. package/src/heading/README.md +4 -0
  327. package/src/heading/block.json +5 -0
  328. package/src/home-link/README.md +6 -0
  329. package/src/home-link/block.json +12 -0
  330. package/src/icon/components/custom-inserter/index.jsx +5 -1
  331. package/src/icon/edit.jsx +68 -7
  332. package/src/icon/index.php +1 -1
  333. package/src/image/index.php +3 -4
  334. package/src/image/style.scss +14 -2
  335. package/src/image/test/use-open-image-media-editor-modal.jsdom.test.js +122 -60
  336. package/src/image/use-open-image-media-editor-modal.js +37 -41
  337. package/src/image/view.js +64 -68
  338. package/src/latest-comments/README.md +3 -0
  339. package/src/latest-comments/block.json +10 -0
  340. package/src/latest-posts/README.md +3 -0
  341. package/src/latest-posts/block.json +4 -0
  342. package/src/list/README.md +6 -0
  343. package/src/list/block.json +12 -1
  344. package/src/list-item/README.md +6 -0
  345. package/src/list-item/block.json +8 -1
  346. package/src/list-item/index.js +5 -0
  347. package/src/loginout/README.md +3 -0
  348. package/src/loginout/block.json +4 -0
  349. package/src/math/README.md +3 -0
  350. package/src/math/block.json +4 -0
  351. package/src/media-text/README.md +17 -0
  352. package/src/media-text/block.json +18 -0
  353. package/src/media-text/style.scss +5 -1
  354. package/src/navigation/test/use-navigation-menu.jsdom.test.js +1 -1
  355. package/src/navigation-link/README.md +1 -1
  356. package/src/navigation-link/link-ui/index.jsx +60 -27
  357. package/src/navigation-link/link-ui/test/get-suggestions-query.jsdom.test.js +67 -0
  358. package/src/navigation-link/shared/index.js +4 -0
  359. package/src/navigation-link/shared/test/use-block-suggestions.jsdom.test.js +158 -0
  360. package/src/navigation-link/shared/test/use-entity-binding.jsdom.test.js +1 -7
  361. package/src/navigation-link/shared/use-block-suggestions.js +192 -0
  362. package/src/page-list/README.md +3 -0
  363. package/src/page-list/block.json +4 -0
  364. package/src/paragraph/README.md +1 -0
  365. package/src/paragraph/block.json +1 -0
  366. package/src/playlist/test/edit-component.jsdom.test.jsx +11 -11
  367. package/src/playlist-track/test/edit.jsdom.test.jsx +3 -3
  368. package/src/post-author-biography/README.md +1 -0
  369. package/src/post-author-biography/block.json +1 -0
  370. package/src/post-comments-form/README.md +3 -0
  371. package/src/post-comments-form/block.json +5 -0
  372. package/src/post-content/README.md +1 -0
  373. package/src/post-content/block.json +2 -1
  374. package/src/post-excerpt/README.md +3 -0
  375. package/src/post-excerpt/block.json +4 -0
  376. package/src/post-featured-image/block.json +1 -0
  377. package/src/post-featured-image/edit.jsx +2 -2
  378. package/src/post-terms/README.md +3 -0
  379. package/src/post-terms/block.json +4 -0
  380. package/src/post-time-to-read/README.md +3 -0
  381. package/src/post-time-to-read/block.json +4 -0
  382. package/src/post-title/README.md +3 -0
  383. package/src/post-title/block.json +4 -0
  384. package/src/preformatted/README.md +3 -0
  385. package/src/preformatted/block.json +4 -0
  386. package/src/pullquote/README.md +1 -0
  387. package/src/pullquote/block.json +2 -1
  388. package/src/query-no-results/README.md +3 -0
  389. package/src/query-no-results/block.json +4 -0
  390. package/src/query-pagination/README.md +4 -0
  391. package/src/query-pagination/block.json +17 -0
  392. package/src/query-pagination/style.scss +3 -0
  393. package/src/query-total/README.md +3 -0
  394. package/src/query-total/block.json +4 -0
  395. package/src/quote/README.md +2 -0
  396. package/src/quote/block.json +2 -0
  397. package/src/read-more/README.md +3 -0
  398. package/src/read-more/block.json +5 -0
  399. package/src/rss/README.md +3 -0
  400. package/src/rss/block.json +4 -0
  401. package/src/search/README.md +1 -0
  402. package/src/search/block.json +2 -1
  403. package/src/site-tagline/README.md +3 -0
  404. package/src/site-tagline/block.json +4 -0
  405. package/src/site-title/README.md +3 -0
  406. package/src/site-title/block.json +4 -0
  407. package/src/social-links/README.md +1 -0
  408. package/src/social-links/block.json +1 -0
  409. package/src/tab-list/README.md +2 -0
  410. package/src/tab-list/block.json +4 -0
  411. package/src/tab-list/edit.jsx +3 -0
  412. package/src/tab-list/save.jsx +3 -0
  413. package/src/tab-panels/README.md +2 -0
  414. package/src/tab-panels/block.json +3 -0
  415. package/src/table/editor.scss +8 -2
  416. package/src/table/style.scss +4 -4
  417. package/src/tabs/README.md +2 -0
  418. package/src/tabs/block.json +3 -0
  419. package/src/tag-cloud/style.scss +1 -1
  420. package/src/template-part/index.php +16 -3
  421. package/src/term-count/README.md +4 -0
  422. package/src/term-count/block.json +5 -0
  423. package/src/term-description/README.md +3 -0
  424. package/src/term-description/block.json +4 -0
  425. package/src/term-name/README.md +4 -0
  426. package/src/term-name/block.json +6 -1
  427. package/src/term-template/README.md +3 -0
  428. package/src/term-template/block.json +4 -0
  429. package/src/utils/test/waveform-player-auto-init.jsdom.test.js +25 -0
  430. package/src/utils/test/waveform-player-dependency.jsdom.test.js +7 -60
  431. package/src/utils/test/waveform-utils.browser.test.js +3 -15
  432. package/src/utils/waveform-utils.js +1 -1
  433. package/src/verse/README.md +4 -0
  434. package/src/verse/block.json +4 -0
  435. package/src/verse/style.scss +11 -2
  436. package/src/video/README.md +4 -0
  437. package/src/video/block.json +7 -1
  438. package/src/video/edit.jsx +13 -2
  439. package/build/columns/utils.cjs +0 -112
  440. package/build/columns/utils.cjs.map +0 -7
  441. package/build-module/columns/utils.mjs +0 -78
  442. package/build-module/columns/utils.mjs.map +0 -7
  443. package/src/columns/test/utils.js +0 -331
  444. package/src/columns/utils.js +0 -176
@@ -1,6 +1,6 @@
1
1
  // packages/block-library/src/icon/edit.jsx
2
2
  import clsx from "clsx";
3
- import { __ } from "@wordpress/i18n";
3
+ import { __, sprintf } from "@wordpress/i18n";
4
4
  import {
5
5
  DropdownMenu,
6
6
  TextControl,
@@ -23,6 +23,7 @@ import {
23
23
  __experimentalGetSpacingClassesAndStyles as useSpacingProps,
24
24
  getDimensionsClassesAndStyles as useDimensionsProps
25
25
  } from "@wordpress/block-editor";
26
+ import { getBlockBindingsSource } from "@wordpress/blocks";
26
27
  import { useState } from "@wordpress/element";
27
28
  import { SVG, Rect, Path } from "@wordpress/primitives";
28
29
  import { useSelect } from "@wordpress/data";
@@ -31,6 +32,7 @@ import { useToolsPanelDropdownMenuProps } from "../utils/hooks.mjs";
31
32
  import HtmlRenderer from "../utils/html-renderer.mjs";
32
33
  import { CustomInserterModal } from "./components/index.mjs";
33
34
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
35
+ var ICON_NAME_REGEX = /^[a-z0-9](?:[a-z0-9_-]*[a-z0-9])?\/[a-z0-9](?:[a-z0-9_-]*[a-z0-9])?$/;
34
36
  var IconPlaceholder = ({ className, style }) => /* @__PURE__ */ jsxs(
35
37
  SVG,
36
38
  {
@@ -55,10 +57,41 @@ var IconPlaceholder = ({ className, style }) => /* @__PURE__ */ jsxs(
55
57
  ]
56
58
  }
57
59
  );
58
- function Edit({ attributes, setAttributes }) {
59
- const { icon, ariaLabel, flipHorizontal, flipVertical, rotation } = attributes;
60
+ function Edit({ attributes, setAttributes, isSelected, context }) {
61
+ const {
62
+ icon,
63
+ ariaLabel,
64
+ flipHorizontal,
65
+ flipVertical,
66
+ rotation,
67
+ metadata
68
+ } = attributes;
60
69
  const [isInserterOpen, setInserterOpen] = useState(false);
61
70
  const isContentOnlyMode = useBlockEditingMode() === "contentOnly";
71
+ const { isIconBindingReadOnly = false, iconBindingReadOnlyMessage } = useSelect(
72
+ (select) => {
73
+ if (!isSelected) {
74
+ return {};
75
+ }
76
+ const iconBinding = metadata?.bindings?.icon;
77
+ const blockBindingsSource = getBlockBindingsSource(
78
+ iconBinding?.source
79
+ );
80
+ return {
81
+ isIconBindingReadOnly: !!iconBinding && !blockBindingsSource?.canUserEditValue?.({
82
+ select,
83
+ context,
84
+ args: iconBinding.args
85
+ }),
86
+ iconBindingReadOnlyMessage: blockBindingsSource?.label ? sprintf(
87
+ /* translators: %s: Label of the bindings source. */
88
+ __("Connected to %s"),
89
+ blockBindingsSource.label
90
+ ) : __("Connected to dynamic data")
91
+ };
92
+ },
93
+ [context, isSelected, metadata?.bindings?.icon]
94
+ );
62
95
  const colorProps = useColorProps(attributes);
63
96
  const spacingProps = useSpacingProps({
64
97
  style: {
@@ -71,8 +104,14 @@ function Edit({ attributes, setAttributes }) {
71
104
  const dimensionsProps = useDimensionsProps(attributes);
72
105
  const selectedIcon = useSelect(
73
106
  (select) => {
74
- const { getEntityRecord } = select(coreDataStore);
75
- return icon ? getEntityRecord("root", "icon", icon) : null;
107
+ if (typeof icon !== "string" || !ICON_NAME_REGEX.test(icon)) {
108
+ return null;
109
+ }
110
+ return select(coreDataStore).getEntityRecord(
111
+ "root",
112
+ "icon",
113
+ icon
114
+ );
76
115
  },
77
116
  [icon]
78
117
  );
@@ -82,6 +121,7 @@ function Edit({ attributes, setAttributes }) {
82
121
  "is-flip-vertical": flipVertical
83
122
  };
84
123
  const rotationStyle = rotation ? { rotate: `${rotation}deg` } : {};
124
+ const iconToolbarButtonLabel = icon ? __("Replace") : __("Choose icon");
85
125
  const blockControls = /* @__PURE__ */ jsxs(Fragment, { children: [
86
126
  icon && /* @__PURE__ */ jsxs(BlockControls, { group: "block", children: [
87
127
  /* @__PURE__ */ jsx(
@@ -121,10 +161,14 @@ function Edit({ attributes, setAttributes }) {
121
161
  /* @__PURE__ */ jsx(
122
162
  ToolbarButton,
123
163
  {
164
+ disabled: isIconBindingReadOnly,
165
+ label: isIconBindingReadOnly ? iconBindingReadOnlyMessage : void 0,
166
+ showTooltip: isIconBindingReadOnly,
167
+ "aria-label": isIconBindingReadOnly ? iconToolbarButtonLabel : void 0,
124
168
  onClick: () => {
125
169
  setInserterOpen(true);
126
170
  },
127
- children: icon ? __("Replace") : __("Choose icon")
171
+ children: iconToolbarButtonLabel
128
172
  }
129
173
  ),
130
174
  isContentOnlyMode && icon && // Add some extra controls for content attributes when content only mode is active.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/icon/edit.jsx"],
4
- "sourcesContent": ["import clsx from 'clsx';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tDropdownMenu,\n\tTextControl,\n\tToolbarButton,\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n} from '@wordpress/components';\nimport {\n\tflipHorizontal as flipHorizontalIcon,\n\tflipVertical as flipVerticalIcon,\n\trotateRight,\n} from '@wordpress/icons';\nimport {\n\tBlockControls,\n\tInspectorControls,\n\tuseBlockProps,\n\tuseBlockEditingMode,\n\t__experimentalUseColorProps as useColorProps,\n\t__experimentalUseBorderProps as useBorderProps,\n\t__experimentalGetSpacingClassesAndStyles as useSpacingProps,\n\tgetDimensionsClassesAndStyles as useDimensionsProps,\n} from '@wordpress/block-editor';\nimport { useState } from '@wordpress/element';\nimport { SVG, Rect, Path } from '@wordpress/primitives';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreDataStore } from '@wordpress/core-data';\nimport { useToolsPanelDropdownMenuProps } from '../utils/hooks';\nimport HtmlRenderer from '../utils/html-renderer';\nimport { CustomInserterModal } from './components';\n\nconst IconPlaceholder = ( { className, style } ) => (\n\t<SVG\n\t\txmlns=\"http://www.w3.org/2000/svg\"\n\t\tviewBox=\"0 0 60 60\"\n\t\tpreserveAspectRatio=\"none\"\n\t\tfill=\"none\"\n\t\taria-hidden=\"true\"\n\t\tclassName={ clsx( 'wp-block-icon__placeholder', className ) }\n\t\tstyle={ style }\n\t>\n\t\t<Rect width=\"60\" height=\"60\" fill=\"currentColor\" fillOpacity={ 0.1 } />\n\t\t<Path\n\t\t\tvectorEffect=\"non-scaling-stroke\"\n\t\t\tstroke=\"currentColor\"\n\t\t\tstrokeOpacity={ 0.25 }\n\t\t\td=\"M60 60 0 0\"\n\t\t/>\n\t</SVG>\n);\n\nexport function Edit( { attributes, setAttributes } ) {\n\tconst { icon, ariaLabel, flipHorizontal, flipVertical, rotation } =\n\t\tattributes;\n\n\tconst [ isInserterOpen, setInserterOpen ] = useState( false );\n\n\tconst isContentOnlyMode = useBlockEditingMode() === 'contentOnly';\n\n\tconst colorProps = useColorProps( attributes );\n\t// Only padding is applied to the inner SVG element, matching the front\n\t// end. The margin support is serialized to the block wrapper instead.\n\tconst spacingProps = useSpacingProps( {\n\t\tstyle: {\n\t\t\tspacing: {\n\t\t\t\tpadding: attributes.style?.spacing?.padding,\n\t\t\t},\n\t\t},\n\t} );\n\tconst borderProps = useBorderProps( attributes );\n\tconst dimensionsProps = useDimensionsProps( attributes );\n\n\tconst selectedIcon = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecord } = select( coreDataStore );\n\t\t\treturn icon ? getEntityRecord( 'root', 'icon', icon ) : null;\n\t\t},\n\t\t[ icon ]\n\t);\n\n\tconst iconToDisplay = selectedIcon?.content || '';\n\n\tconst flipClasses = {\n\t\t'is-flip-horizontal': flipHorizontal,\n\t\t'is-flip-vertical': flipVertical,\n\t};\n\n\tconst rotationStyle = rotation ? { rotate: `${ rotation }deg` } : {};\n\n\tconst blockControls = (\n\t\t<>\n\t\t\t{ icon && (\n\t\t\t\t<BlockControls group=\"block\">\n\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\ticon={ flipHorizontalIcon }\n\t\t\t\t\t\tlabel={ __( 'Flip horizontal' ) }\n\t\t\t\t\t\tisPressed={ flipHorizontal }\n\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tflipHorizontal: ! flipHorizontal,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\ticon={ flipVerticalIcon }\n\t\t\t\t\t\tlabel={ __( 'Flip vertical' ) }\n\t\t\t\t\t\tisPressed={ flipVertical }\n\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tflipVertical: ! flipVertical,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\ticon={ rotateRight }\n\t\t\t\t\t\tlabel={ __( 'Rotate' ) }\n\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\trotation: ( ( rotation || 0 ) + 90 ) % 360,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t</BlockControls>\n\t\t\t) }\n\t\t\t<BlockControls group=\"other\">\n\t\t\t\t<ToolbarButton\n\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\tsetInserterOpen( true );\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t{ icon ? __( 'Replace' ) : __( 'Choose icon' ) }\n\t\t\t\t</ToolbarButton>\n\t\t\t\t{ isContentOnlyMode && icon && (\n\t\t\t\t\t// Add some extra controls for content attributes when content only mode is active.\n\t\t\t\t\t// With content only mode active, the inspector is hidden, so users need another way\n\t\t\t\t\t// to edit these attributes.\n\t\t\t\t\t<DropdownMenu\n\t\t\t\t\t\ticon=\"\"\n\t\t\t\t\t\ttoggleProps={ {\n\t\t\t\t\t\t\tas: ToolbarButton,\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tpopoverProps={ {\n\t\t\t\t\t\t\tclassName: 'is-alternate',\n\t\t\t\t\t\t} }\n\t\t\t\t\t\ttext={ __( 'Label' ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ () => (\n\t\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t\tclassName=\"wp-block-icon__toolbar-content\"\n\t\t\t\t\t\t\t\tlabel={ __( 'Label' ) }\n\t\t\t\t\t\t\t\tvalue={ ariaLabel || '' }\n\t\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\tariaLabel: value,\n\t\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t\t'Briefly describe the icon to help screen reader users. Leave blank for decorative icons.'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</DropdownMenu>\n\t\t\t\t) }\n\t\t\t</BlockControls>\n\t\t</>\n\t);\n\tconst dropdownMenuProps = useToolsPanelDropdownMenuProps();\n\tconst inspectorControls = icon && (\n\t\t<>\n\t\t\t<InspectorControls group=\"settings\">\n\t\t\t\t<ToolsPanel\n\t\t\t\t\tlabel={ __( 'Settings' ) }\n\t\t\t\t\tresetAll={ () =>\n\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\tariaLabel: undefined,\n\t\t\t\t\t\t} )\n\t\t\t\t\t}\n\t\t\t\t\tdropdownMenuProps={ dropdownMenuProps }\n\t\t\t\t>\n\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\tlabel={ __( 'Label' ) }\n\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t\thasValue={ () => !! ariaLabel }\n\t\t\t\t\t\tonDeselect={ () =>\n\t\t\t\t\t\t\tsetAttributes( { ariaLabel: undefined } )\n\t\t\t\t\t\t}\n\t\t\t\t\t>\n\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\tlabel={ __( 'Label' ) }\n\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t'Briefly describe the icon to help screen reader users. Leave blank for decorative icons.'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tvalue={ ariaLabel || '' }\n\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\tsetAttributes( { ariaLabel: value } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t</ToolsPanel>\n\t\t\t</InspectorControls>\n\t\t</>\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t{ blockControls }\n\t\t\t{ inspectorControls }\n\t\t\t<div { ...useBlockProps() }>\n\t\t\t\t{ iconToDisplay ? (\n\t\t\t\t\t<HtmlRenderer\n\t\t\t\t\t\thtml={ iconToDisplay }\n\t\t\t\t\t\twrapperProps={ {\n\t\t\t\t\t\t\tclassName: clsx(\n\t\t\t\t\t\t\t\tcolorProps.className,\n\t\t\t\t\t\t\t\tborderProps.className,\n\t\t\t\t\t\t\t\tspacingProps.className,\n\t\t\t\t\t\t\t\tdimensionsProps.className,\n\t\t\t\t\t\t\t\tflipClasses\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tstyle: {\n\t\t\t\t\t\t\t\t...colorProps.style,\n\t\t\t\t\t\t\t\t...borderProps.style,\n\t\t\t\t\t\t\t\t...spacingProps.style,\n\t\t\t\t\t\t\t\t...dimensionsProps.style,\n\t\t\t\t\t\t\t\t...rotationStyle,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t) : (\n\t\t\t\t\t<IconPlaceholder\n\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\tborderProps.className,\n\t\t\t\t\t\t\tspacingProps.className,\n\t\t\t\t\t\t\tdimensionsProps.className,\n\t\t\t\t\t\t\tflipClasses\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tstyle={ {\n\t\t\t\t\t\t\t...borderProps.style,\n\t\t\t\t\t\t\t...spacingProps.style,\n\t\t\t\t\t\t\t...dimensionsProps.style,\n\t\t\t\t\t\t\t...rotationStyle,\n\t\t\t\t\t\t\theight: 'auto',\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t\t{ isInserterOpen && (\n\t\t\t\t<CustomInserterModal\n\t\t\t\t\tonClose={ () => setInserterOpen( false ) }\n\t\t\t\t\tvalue={ attributes.icon }\n\t\t\t\t\tonChange={ ( name ) => {\n\t\t\t\t\t\tsetAttributes( { icon: name } );\n\t\t\t\t\t\tsetInserterOpen( false );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default Edit;\n"],
5
- "mappings": ";AAAA,OAAO,UAAU;AACjB,SAAS,UAAU;AACnB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA,4BAA4B;AAAA,EAC5B,gCAAgC;AAAA,OAC1B;AACP;AAAA,EACC,kBAAkB;AAAA,EAClB,gBAAgB;AAAA,EAChB;AAAA,OACM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,+BAA+B;AAAA,EAC/B,gCAAgC;AAAA,EAChC,4CAA4C;AAAA,EAC5C,iCAAiC;AAAA,OAC3B;AACP,SAAS,gBAAgB;AACzB,SAAS,KAAK,MAAM,YAAY;AAChC,SAAS,iBAAiB;AAC1B,SAAS,SAAS,qBAAqB;AACvC,SAAS,sCAAsC;AAC/C,OAAO,kBAAkB;AACzB,SAAS,2BAA2B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AQ;AAAA,UACP,GAAG,YAAY;AAAA,UACf,GAAG,aAAa;AAAA,UAChB,GAAG,gBAAgB;AAAA,UACnB,GAAG;AAAA,UACH,QAAQ;AAAA,QACT;AAAA;AAAA,IACD,GAEF;AAAA,IACE,kBACD;AAAA,MAAC;AAAA;AAAA,QACA,SAAU,MAAM,gBAAiB,KAAM;AAAA,QACvC,OAAQ,WAAW;AAAA,QACnB,UAAW,CAAE,SAAU;AACtB,wBAAe,EAAE,MAAM,KAAK,CAAE;AAC9B,0BAAiB,KAAM;AAAA,QACxB;AAAA;AAAA,IACD;AAAA,KAEF;AAEF;AAEA,IAAO,eAAQ;",
4
+ "sourcesContent": ["import clsx from 'clsx';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tDropdownMenu,\n\tTextControl,\n\tToolbarButton,\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n} from '@wordpress/components';\nimport {\n\tflipHorizontal as flipHorizontalIcon,\n\tflipVertical as flipVerticalIcon,\n\trotateRight,\n} from '@wordpress/icons';\nimport {\n\tBlockControls,\n\tInspectorControls,\n\tuseBlockProps,\n\tuseBlockEditingMode,\n\t__experimentalUseColorProps as useColorProps,\n\t__experimentalUseBorderProps as useBorderProps,\n\t__experimentalGetSpacingClassesAndStyles as useSpacingProps,\n\tgetDimensionsClassesAndStyles as useDimensionsProps,\n} from '@wordpress/block-editor';\nimport { getBlockBindingsSource } from '@wordpress/blocks';\nimport { useState } from '@wordpress/element';\nimport { SVG, Rect, Path } from '@wordpress/primitives';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreDataStore } from '@wordpress/core-data';\nimport { useToolsPanelDropdownMenuProps } from '../utils/hooks';\nimport HtmlRenderer from '../utils/html-renderer';\nimport { CustomInserterModal } from './components';\n\n// Matches the icon name pattern accepted by /wp/v2/icons/<name> REST route.\nconst ICON_NAME_REGEX =\n\t/^[a-z0-9](?:[a-z0-9_-]*[a-z0-9])?\\/[a-z0-9](?:[a-z0-9_-]*[a-z0-9])?$/;\n\nconst IconPlaceholder = ( { className, style } ) => (\n\t<SVG\n\t\txmlns=\"http://www.w3.org/2000/svg\"\n\t\tviewBox=\"0 0 60 60\"\n\t\tpreserveAspectRatio=\"none\"\n\t\tfill=\"none\"\n\t\taria-hidden=\"true\"\n\t\tclassName={ clsx( 'wp-block-icon__placeholder', className ) }\n\t\tstyle={ style }\n\t>\n\t\t<Rect width=\"60\" height=\"60\" fill=\"currentColor\" fillOpacity={ 0.1 } />\n\t\t<Path\n\t\t\tvectorEffect=\"non-scaling-stroke\"\n\t\t\tstroke=\"currentColor\"\n\t\t\tstrokeOpacity={ 0.25 }\n\t\t\td=\"M60 60 0 0\"\n\t\t/>\n\t</SVG>\n);\n\nexport function Edit( { attributes, setAttributes, isSelected, context } ) {\n\tconst {\n\t\ticon,\n\t\tariaLabel,\n\t\tflipHorizontal,\n\t\tflipVertical,\n\t\trotation,\n\t\tmetadata,\n\t} = attributes;\n\n\tconst [ isInserterOpen, setInserterOpen ] = useState( false );\n\n\tconst isContentOnlyMode = useBlockEditingMode() === 'contentOnly';\n\tconst { isIconBindingReadOnly = false, iconBindingReadOnlyMessage } =\n\t\tuseSelect(\n\t\t\t( select ) => {\n\t\t\t\tif ( ! isSelected ) {\n\t\t\t\t\treturn {};\n\t\t\t\t}\n\n\t\t\t\tconst iconBinding = metadata?.bindings?.icon;\n\t\t\t\tconst blockBindingsSource = getBlockBindingsSource(\n\t\t\t\t\ticonBinding?.source\n\t\t\t\t);\n\n\t\t\t\treturn {\n\t\t\t\t\tisIconBindingReadOnly:\n\t\t\t\t\t\t!! iconBinding &&\n\t\t\t\t\t\t! blockBindingsSource?.canUserEditValue?.( {\n\t\t\t\t\t\t\tselect,\n\t\t\t\t\t\t\tcontext,\n\t\t\t\t\t\t\targs: iconBinding.args,\n\t\t\t\t\t\t} ),\n\t\t\t\t\ticonBindingReadOnlyMessage: blockBindingsSource?.label\n\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t/* translators: %s: Label of the bindings source. */\n\t\t\t\t\t\t\t\t__( 'Connected to %s' ),\n\t\t\t\t\t\t\t\tblockBindingsSource.label\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t: __( 'Connected to dynamic data' ),\n\t\t\t\t};\n\t\t\t},\n\t\t\t[ context, isSelected, metadata?.bindings?.icon ]\n\t\t);\n\n\tconst colorProps = useColorProps( attributes );\n\t// Only padding is applied to the inner SVG element, matching the front\n\t// end. The margin support is serialized to the block wrapper instead.\n\tconst spacingProps = useSpacingProps( {\n\t\tstyle: {\n\t\t\tspacing: {\n\t\t\t\tpadding: attributes.style?.spacing?.padding,\n\t\t\t},\n\t\t},\n\t} );\n\tconst borderProps = useBorderProps( attributes );\n\tconst dimensionsProps = useDimensionsProps( attributes );\n\n\tconst selectedIcon = useSelect(\n\t\t( select ) => {\n\t\t\tif ( typeof icon !== 'string' || ! ICON_NAME_REGEX.test( icon ) ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn select( coreDataStore ).getEntityRecord(\n\t\t\t\t'root',\n\t\t\t\t'icon',\n\t\t\t\ticon\n\t\t\t);\n\t\t},\n\t\t[ icon ]\n\t);\n\n\tconst iconToDisplay = selectedIcon?.content || '';\n\n\tconst flipClasses = {\n\t\t'is-flip-horizontal': flipHorizontal,\n\t\t'is-flip-vertical': flipVertical,\n\t};\n\n\tconst rotationStyle = rotation ? { rotate: `${ rotation }deg` } : {};\n\tconst iconToolbarButtonLabel = icon ? __( 'Replace' ) : __( 'Choose icon' );\n\n\tconst blockControls = (\n\t\t<>\n\t\t\t{ icon && (\n\t\t\t\t<BlockControls group=\"block\">\n\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\ticon={ flipHorizontalIcon }\n\t\t\t\t\t\tlabel={ __( 'Flip horizontal' ) }\n\t\t\t\t\t\tisPressed={ flipHorizontal }\n\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tflipHorizontal: ! flipHorizontal,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\ticon={ flipVerticalIcon }\n\t\t\t\t\t\tlabel={ __( 'Flip vertical' ) }\n\t\t\t\t\t\tisPressed={ flipVertical }\n\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tflipVertical: ! flipVertical,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\ticon={ rotateRight }\n\t\t\t\t\t\tlabel={ __( 'Rotate' ) }\n\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\trotation: ( ( rotation || 0 ) + 90 ) % 360,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t</BlockControls>\n\t\t\t) }\n\t\t\t<BlockControls group=\"other\">\n\t\t\t\t<ToolbarButton\n\t\t\t\t\tdisabled={ isIconBindingReadOnly }\n\t\t\t\t\tlabel={\n\t\t\t\t\t\tisIconBindingReadOnly\n\t\t\t\t\t\t\t? iconBindingReadOnlyMessage\n\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t}\n\t\t\t\t\tshowTooltip={ isIconBindingReadOnly }\n\t\t\t\t\taria-label={\n\t\t\t\t\t\tisIconBindingReadOnly\n\t\t\t\t\t\t\t? iconToolbarButtonLabel\n\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t}\n\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\tsetInserterOpen( true );\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t{ iconToolbarButtonLabel }\n\t\t\t\t</ToolbarButton>\n\t\t\t\t{ isContentOnlyMode && icon && (\n\t\t\t\t\t// Add some extra controls for content attributes when content only mode is active.\n\t\t\t\t\t// With content only mode active, the inspector is hidden, so users need another way\n\t\t\t\t\t// to edit these attributes.\n\t\t\t\t\t<DropdownMenu\n\t\t\t\t\t\ticon=\"\"\n\t\t\t\t\t\ttoggleProps={ {\n\t\t\t\t\t\t\tas: ToolbarButton,\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tpopoverProps={ {\n\t\t\t\t\t\t\tclassName: 'is-alternate',\n\t\t\t\t\t\t} }\n\t\t\t\t\t\ttext={ __( 'Label' ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ () => (\n\t\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t\tclassName=\"wp-block-icon__toolbar-content\"\n\t\t\t\t\t\t\t\tlabel={ __( 'Label' ) }\n\t\t\t\t\t\t\t\tvalue={ ariaLabel || '' }\n\t\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\tariaLabel: value,\n\t\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t\t'Briefly describe the icon to help screen reader users. Leave blank for decorative icons.'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</DropdownMenu>\n\t\t\t\t) }\n\t\t\t</BlockControls>\n\t\t</>\n\t);\n\tconst dropdownMenuProps = useToolsPanelDropdownMenuProps();\n\tconst inspectorControls = icon && (\n\t\t<>\n\t\t\t<InspectorControls group=\"settings\">\n\t\t\t\t<ToolsPanel\n\t\t\t\t\tlabel={ __( 'Settings' ) }\n\t\t\t\t\tresetAll={ () =>\n\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\tariaLabel: undefined,\n\t\t\t\t\t\t} )\n\t\t\t\t\t}\n\t\t\t\t\tdropdownMenuProps={ dropdownMenuProps }\n\t\t\t\t>\n\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\tlabel={ __( 'Label' ) }\n\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t\thasValue={ () => !! ariaLabel }\n\t\t\t\t\t\tonDeselect={ () =>\n\t\t\t\t\t\t\tsetAttributes( { ariaLabel: undefined } )\n\t\t\t\t\t\t}\n\t\t\t\t\t>\n\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\tlabel={ __( 'Label' ) }\n\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t'Briefly describe the icon to help screen reader users. Leave blank for decorative icons.'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tvalue={ ariaLabel || '' }\n\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\tsetAttributes( { ariaLabel: value } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t</ToolsPanel>\n\t\t\t</InspectorControls>\n\t\t</>\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t{ blockControls }\n\t\t\t{ inspectorControls }\n\t\t\t<div { ...useBlockProps() }>\n\t\t\t\t{ iconToDisplay ? (\n\t\t\t\t\t<HtmlRenderer\n\t\t\t\t\t\thtml={ iconToDisplay }\n\t\t\t\t\t\twrapperProps={ {\n\t\t\t\t\t\t\tclassName: clsx(\n\t\t\t\t\t\t\t\tcolorProps.className,\n\t\t\t\t\t\t\t\tborderProps.className,\n\t\t\t\t\t\t\t\tspacingProps.className,\n\t\t\t\t\t\t\t\tdimensionsProps.className,\n\t\t\t\t\t\t\t\tflipClasses\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tstyle: {\n\t\t\t\t\t\t\t\t...colorProps.style,\n\t\t\t\t\t\t\t\t...borderProps.style,\n\t\t\t\t\t\t\t\t...spacingProps.style,\n\t\t\t\t\t\t\t\t...dimensionsProps.style,\n\t\t\t\t\t\t\t\t...rotationStyle,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t) : (\n\t\t\t\t\t<IconPlaceholder\n\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\tborderProps.className,\n\t\t\t\t\t\t\tspacingProps.className,\n\t\t\t\t\t\t\tdimensionsProps.className,\n\t\t\t\t\t\t\tflipClasses\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tstyle={ {\n\t\t\t\t\t\t\t...borderProps.style,\n\t\t\t\t\t\t\t...spacingProps.style,\n\t\t\t\t\t\t\t...dimensionsProps.style,\n\t\t\t\t\t\t\t...rotationStyle,\n\t\t\t\t\t\t\theight: 'auto',\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t\t{ isInserterOpen && (\n\t\t\t\t<CustomInserterModal\n\t\t\t\t\tonClose={ () => setInserterOpen( false ) }\n\t\t\t\t\tvalue={ attributes.icon }\n\t\t\t\t\tonChange={ ( name ) => {\n\t\t\t\t\t\tsetAttributes( { icon: name } );\n\t\t\t\t\t\tsetInserterOpen( false );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default Edit;\n"],
5
+ "mappings": ";AAAA,OAAO,UAAU;AACjB,SAAS,IAAI,eAAe;AAC5B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA,4BAA4B;AAAA,EAC5B,gCAAgC;AAAA,OAC1B;AACP;AAAA,EACC,kBAAkB;AAAA,EAClB,gBAAgB;AAAA,EAChB;AAAA,OACM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,+BAA+B;AAAA,EAC/B,gCAAgC;AAAA,EAChC,4CAA4C;AAAA,EAC5C,iCAAiC;AAAA,OAC3B;AACP,SAAS,8BAA8B;AACvC,SAAS,gBAAgB;AACzB,SAAS,KAAK,MAAM,YAAY;AAChC,SAAS,iBAAiB;AAC1B,SAAS,SAAS,qBAAqB;AACvC,SA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6
6
  "names": []
7
7
  }
@@ -124,7 +124,7 @@ function useOpenImageMediaEditorModal({
124
124
  onClose,
125
125
  onUrlChange
126
126
  }) {
127
- const { id, url, alt, caption, sizeSlug, linkDestination } = attributes;
127
+ const { id, url, alt, caption, sizeSlug, linkDestination, href } = attributes;
128
128
  const registry = useRegistry();
129
129
  const openMediaEditorModal = useSelect(
130
130
  (select) => select(blockEditorStore).getSettings()[openMediaEditorModalKey],
@@ -136,11 +136,11 @@ function useOpenImageMediaEditorModal({
136
136
  alt,
137
137
  caption: caption?.toString(),
138
138
  sizeSlug,
139
- linkDestination
139
+ linkDestination,
140
+ href
140
141
  });
141
142
  const mediaEditorMetadataBaselineRef = useRef();
142
143
  const mediaEditorMetadataSyncRequestRef = useRef(0);
143
- const mediaEditorUndoMetadataRef = useRef();
144
144
  useEffect(() => {
145
145
  blockAttributesRef.current = {
146
146
  id,
@@ -148,9 +148,10 @@ function useOpenImageMediaEditorModal({
148
148
  alt,
149
149
  caption: caption?.toString(),
150
150
  sizeSlug,
151
- linkDestination
151
+ linkDestination,
152
+ href
152
153
  };
153
- }, [alt, caption, id, linkDestination, sizeSlug, url]);
154
+ }, [alt, caption, href, id, linkDestination, sizeSlug, url]);
154
155
  const getCachedAttachmentRecord = useCallback(
155
156
  (attachmentId) => registry.select(coreStore).getEditedEntityRecord(
156
157
  "postType",
@@ -187,19 +188,19 @@ function useOpenImageMediaEditorModal({
187
188
  [registry, resolveAttachmentRecord]
188
189
  );
189
190
  const handleMediaUpdate = useCallback(
190
- async ({ id: newId, url: newUrl }) => {
191
+ async ({ id: newId, url: newUrl }, undoState) => {
191
192
  if (typeof newId !== "number") {
192
193
  return;
193
194
  }
194
195
  const originalAttachment = mediaEditorMetadataBaselineRef.current;
195
196
  mediaEditorMetadataBaselineRef.current = void 0;
196
- const undoMetadata = mediaEditorUndoMetadataRef.current;
197
- mediaEditorUndoMetadataRef.current = void 0;
198
197
  const syncRequest = ++mediaEditorMetadataSyncRequestRef.current;
199
198
  const nextAttributes = {};
200
199
  const currentBlockAttributes = blockAttributesRef.current;
201
200
  const isNewAttachment = newId !== currentBlockAttributes.id;
202
201
  if (isNewAttachment) {
202
+ undoState.undoAttributes.id = currentBlockAttributes.id;
203
+ undoState.undoAttributes.url = currentBlockAttributes.url;
203
204
  nextAttributes.id = newId;
204
205
  nextAttributes.url = newUrl ?? currentBlockAttributes.url;
205
206
  if (nextAttributes.url !== currentBlockAttributes.url) {
@@ -213,7 +214,7 @@ function useOpenImageMediaEditorModal({
213
214
  }
214
215
  if (originalAttachment || isNewAttachment) {
215
216
  const resolvedAttachment = await resolveFreshAttachmentRecord(newId);
216
- if (syncRequest !== mediaEditorMetadataSyncRequestRef.current) {
217
+ if (undoState.isUndone || syncRequest !== mediaEditorMetadataSyncRequestRef.current) {
217
218
  return;
218
219
  }
219
220
  const attachmentRecord = resolvedAttachment ?? getCachedAttachmentRecord(newId);
@@ -229,19 +230,6 @@ function useOpenImageMediaEditorModal({
229
230
  nextAttributes,
230
231
  resolvedMetadataAttributes
231
232
  );
232
- if (isNewAttachment) {
233
- mediaEditorUndoMetadataRef.current = {
234
- id: currentBlockAttributes.id,
235
- attributes: Object.fromEntries(
236
- Object.keys(
237
- resolvedMetadataAttributes
238
- ).map((key) => [
239
- key,
240
- latestBlockAttributes[key]
241
- ])
242
- )
243
- };
244
- }
245
233
  }
246
234
  }
247
235
  if (isNewAttachment) {
@@ -257,10 +245,12 @@ function useOpenImageMediaEditorModal({
257
245
  }
258
246
  }
259
247
  }
260
- if (undoMetadata?.id === newId) {
261
- Object.assign(nextAttributes, undoMetadata.attributes);
262
- }
263
248
  if (Object.keys(nextAttributes).length) {
249
+ for (const key of Object.keys(nextAttributes)) {
250
+ if (!Object.hasOwn(undoState.undoAttributes, key)) {
251
+ undoState.undoAttributes[key] = blockAttributesRef.current[key];
252
+ }
253
+ }
264
254
  blockAttributesRef.current = {
265
255
  ...blockAttributesRef.current,
266
256
  ...nextAttributes
@@ -279,7 +269,6 @@ function useOpenImageMediaEditorModal({
279
269
  if (!id || !openMediaEditorModal) {
280
270
  return;
281
271
  }
282
- mediaEditorUndoMetadataRef.current = void 0;
283
272
  const cachedAttachmentRecord = getCachedAttachmentRecord(id);
284
273
  const fallbackAttachmentRecord = getAttachmentFallbackForEmptyBlockMetadata(
285
274
  blockAttributesRef.current
@@ -288,9 +277,22 @@ function useOpenImageMediaEditorModal({
288
277
  cachedAttachmentRecord
289
278
  ) ? void 0 : await resolveAttachmentRecord(id);
290
279
  mediaEditorMetadataBaselineRef.current = resolvedAttachmentRecord || (hasKnownAttachmentMetadata(cachedAttachmentRecord) ? cachedAttachmentRecord : fallbackAttachmentRecord) || cachedAttachmentRecord;
280
+ const undoState = { undoAttributes: {}, isUndone: false };
291
281
  openMediaEditorModal({
292
282
  id,
293
- onUpdate: handleMediaUpdate,
283
+ onUpdate: (updated) => handleMediaUpdate(updated, undoState),
284
+ onUndo: () => {
285
+ undoState.isUndone = true;
286
+ const { undoAttributes } = undoState;
287
+ if (Object.hasOwn(undoAttributes, "url")) {
288
+ onUrlChange?.(undoAttributes.url);
289
+ }
290
+ blockAttributesRef.current = {
291
+ ...blockAttributesRef.current,
292
+ ...undoAttributes
293
+ };
294
+ setAttributes(undoAttributes);
295
+ },
294
296
  onClose
295
297
  });
296
298
  }, [
@@ -298,8 +300,10 @@ function useOpenImageMediaEditorModal({
298
300
  handleMediaUpdate,
299
301
  id,
300
302
  onClose,
303
+ onUrlChange,
301
304
  openMediaEditorModal,
302
- resolveAttachmentRecord
305
+ resolveAttachmentRecord,
306
+ setAttributes
303
307
  ]);
304
308
  return id && openMediaEditorModal ? openImageMediaEditorModal : void 0;
305
309
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/image/use-open-image-media-editor-modal.js"],
4
- "sourcesContent": ["import { store as coreStore } from '@wordpress/core-data';\nimport {\n\tprivateApis as blockEditorPrivateApis,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\nimport { useRegistry, useSelect } from '@wordpress/data';\nimport { useCallback, useEffect, useRef } from '@wordpress/element';\nimport { unlock } from '../lock-unlock';\nimport {\n\tDEFAULT_MEDIA_SIZE_SLUG,\n\tLINK_DESTINATION_ATTACHMENT,\n\tLINK_DESTINATION_MEDIA,\n} from './constants';\n\nfunction normalizeImageBlockCaption( caption ) {\n\tif ( typeof caption !== 'string' ) {\n\t\treturn '';\n\t}\n\n\tconst textContent = stripHTML( caption ).trim();\n\n\tif ( ! textContent ) {\n\t\treturn '';\n\t}\n\n\treturn caption.replace( /\\n/g, '<br>' );\n}\n\nfunction getAttachmentCaption( attachment ) {\n\tconst caption = attachment?.caption;\n\n\tif ( typeof caption === 'string' ) {\n\t\treturn normalizeImageBlockCaption( caption );\n\t}\n\n\tif (\n\t\tcaption &&\n\t\ttypeof caption === 'object' &&\n\t\tObject.hasOwn( caption, 'raw' )\n\t) {\n\t\treturn normalizeImageBlockCaption( caption.raw );\n\t}\n\n\treturn undefined;\n}\n\nexport function getImageBlockMetadataFromAttachment( attachment ) {\n\treturn {\n\t\talt:\n\t\t\ttypeof attachment?.alt_text === 'string'\n\t\t\t\t? attachment.alt_text\n\t\t\t\t: attachment?.alt || '',\n\t\tcaption: getAttachmentCaption( attachment ),\n\t};\n}\n\nfunction normalizeMetadataAttribute( value ) {\n\treturn value || '';\n}\n\nexport function getSyncedImageBlockAttributes(\n\tcurrentAttributes,\n\toriginalAttachment,\n\tupdatedAttachment\n) {\n\tif ( ! originalAttachment || ! updatedAttachment ) {\n\t\treturn {};\n\t}\n\n\tconst originalMetadata =\n\t\tgetImageBlockMetadataFromAttachment( originalAttachment );\n\tconst updatedMetadata =\n\t\tgetImageBlockMetadataFromAttachment( updatedAttachment );\n\tconst syncedAttributes = {};\n\n\tconst normalizedCurrentAlt = normalizeMetadataAttribute(\n\t\tcurrentAttributes.alt\n\t);\n\tif (\n\t\toriginalMetadata.alt !== updatedMetadata.alt &&\n\t\t( normalizedCurrentAlt === originalMetadata.alt ||\n\t\t\t! normalizedCurrentAlt )\n\t) {\n\t\tsyncedAttributes.alt = updatedMetadata.alt;\n\t}\n\n\tconst normalizedCurrentCaption = normalizeMetadataAttribute(\n\t\tcurrentAttributes.caption\n\t);\n\tif (\n\t\toriginalMetadata.caption !== undefined &&\n\t\tupdatedMetadata.caption !== undefined &&\n\t\toriginalMetadata.caption !== updatedMetadata.caption &&\n\t\t( normalizedCurrentCaption === originalMetadata.caption ||\n\t\t\t! normalizedCurrentCaption )\n\t) {\n\t\tsyncedAttributes.caption = updatedMetadata.caption || undefined;\n\t}\n\n\treturn syncedAttributes;\n}\n\n/**\n * Resolves the attributes needed to keep the selected image size on a new\n * attachment.\n *\n * WordPress skips generating a sub-size larger than the file itself, so the\n * selected size may not exist on the edited image; fall back to full when it\n * doesn't.\n *\n * @param {string|undefined} sizeSlug The block's currently selected size.\n * @param {Object} attachment The new attachment record.\n *\n * @return {Object|undefined} Attributes to apply, if any.\n */\nfunction getNewAttachmentSizeAttributes( sizeSlug, attachment ) {\n\tconst sizes = attachment.media_details?.sizes;\n\n\tif ( ! sizeSlug || sizeSlug === DEFAULT_MEDIA_SIZE_SLUG || ! sizes ) {\n\t\treturn undefined;\n\t}\n\n\tconst sizeUrl = sizes[ sizeSlug ]?.source_url;\n\n\tif ( sizeUrl ) {\n\t\treturn { url: sizeUrl };\n\t}\n\n\tconst fullUrl = attachment.source_url ?? sizes.full?.source_url;\n\n\treturn fullUrl\n\t\t? { url: fullUrl, sizeSlug: DEFAULT_MEDIA_SIZE_SLUG }\n\t\t: undefined;\n}\n\n/**\n * Resolves the link attributes needed to keep the block's link pointing at the\n * new attachment.\n *\n * Only the destinations derived from the attachment follow the edited image. A\n * `custom` link is the user's own URL and a `none` link has nothing to point\n * at, so both are left alone. When the record doesn't carry the field, the\n * existing link is kept rather than cleared.\n *\n * @param {string|undefined} linkDestination The block's link destination.\n * @param {Object} attachment The new attachment record.\n *\n * @return {Object|undefined} Attributes to apply, if any.\n */\nfunction getNewAttachmentLinkAttributes( linkDestination, attachment ) {\n\t// Media file links point at the full-size file, independently of the size\n\t// the block renders.\n\tif ( linkDestination === LINK_DESTINATION_MEDIA ) {\n\t\treturn attachment.source_url\n\t\t\t? { href: attachment.source_url }\n\t\t\t: undefined;\n\t}\n\n\tif ( linkDestination === LINK_DESTINATION_ATTACHMENT ) {\n\t\treturn attachment.link ? { href: attachment.link } : undefined;\n\t}\n\n\treturn undefined;\n}\n\n/**\n * Resolves the block attributes that are derived from the attachment, for an\n * edit that saved to a different one.\n *\n * Editing media (crop, rotate, flip) creates a new attachment with its own\n * generated sub-sizes and its own attachment page, and the media editor\n * reports the full-size file. Without re-deriving these, the size control\n * keeps reporting e.g. \"Medium\" while the block renders the full-size image,\n * and a \"Media file\" or \"Attachment page\" link still points at the image as it\n * was before the edit. Everything else the user set on the block — dimensions,\n * lightbox, title, custom links — is left untouched.\n *\n * @param {Object} blockAttributes The block's current attributes.\n * @param {Object|undefined} attachment The new attachment record.\n *\n * @return {Object|undefined} Attributes to apply, or undefined when the\n * attachment record isn't known yet.\n */\nexport function getNewAttachmentImageBlockAttributes(\n\tblockAttributes,\n\tattachment\n) {\n\tif ( ! attachment ) {\n\t\treturn undefined;\n\t}\n\n\treturn {\n\t\t...getNewAttachmentSizeAttributes(\n\t\t\tblockAttributes.sizeSlug,\n\t\t\tattachment\n\t\t),\n\t\t...getNewAttachmentLinkAttributes(\n\t\t\tblockAttributes.linkDestination,\n\t\t\tattachment\n\t\t),\n\t};\n}\n\nconst { openMediaEditorModalKey } = unlock( blockEditorPrivateApis );\n\nfunction getAttachmentFallbackForEmptyBlockMetadata( { alt, caption } ) {\n\tconst attachment = {};\n\n\tif ( ! alt ) {\n\t\tattachment.alt_text = '';\n\t}\n\n\tif ( ! caption?.toString() ) {\n\t\tattachment.caption = '';\n\t}\n\n\treturn Object.keys( attachment ).length ? attachment : undefined;\n}\n\nfunction hasKnownAttachmentMetadata( attachment ) {\n\tif ( ! attachment ) {\n\t\treturn false;\n\t}\n\n\tconst hasKnownAlt =\n\t\ttypeof attachment.alt_text === 'string' ||\n\t\ttypeof attachment.alt === 'string';\n\tconst hasKnownCaption =\n\t\tgetImageBlockMetadataFromAttachment( attachment ).caption !== undefined;\n\n\treturn hasKnownAlt && hasKnownCaption;\n}\n\nexport function useOpenImageMediaEditorModal( {\n\tattributes,\n\tsetAttributes,\n\tonClose,\n\tonUrlChange,\n} ) {\n\t// Keep this hook private to the Image block and pass the block attributes\n\t// object so the callsite stays compact. Destructure only the attributes\n\t// the update needs to read — those synced from the attachment's metadata,\n\t// and those derived from which attachment the block points at; add more\n\t// here if the sync policy grows.\n\tconst { id, url, alt, caption, sizeSlug, linkDestination } = attributes;\n\tconst registry = useRegistry();\n\tconst openMediaEditorModal = useSelect(\n\t\t( select ) =>\n\t\t\tselect( blockEditorStore ).getSettings()[ openMediaEditorModalKey ],\n\t\t[]\n\t);\n\t// Track the block's current attachment and metadata in a ref so\n\t// handleMediaUpdate can read the latest values without being listed as\n\t// dependencies (which would recreate the callback and re-register the\n\t// onUpdate handler on every block change while the modal is open).\n\tconst blockAttributesRef = useRef( {\n\t\tid,\n\t\turl,\n\t\talt,\n\t\tcaption: caption?.toString(),\n\t\tsizeSlug,\n\t\tlinkDestination,\n\t} );\n\t// Snapshot of the attachment's metadata taken just before the modal opens,\n\t// used as the baseline for detecting what changed during the editing session.\n\tconst mediaEditorMetadataBaselineRef = useRef();\n\t// Incremented on every handleMediaUpdate call; stale async continuations\n\t// check against this to bail out if a newer update has since started.\n\tconst mediaEditorMetadataSyncRequestRef = useRef( 0 );\n\t// The alt text and caption a save overwrote on the block, and the\n\t// attachment it moved the block away from. The media editor's Undo moves\n\t// the block back but reports only that attachment's id and url, so this is\n\t// what lets the update restore the block's own metadata too.\n\tconst mediaEditorUndoMetadataRef = useRef();\n\n\tuseEffect( () => {\n\t\tblockAttributesRef.current = {\n\t\t\tid,\n\t\t\turl,\n\t\t\talt,\n\t\t\tcaption: caption?.toString(),\n\t\t\tsizeSlug,\n\t\t\tlinkDestination,\n\t\t};\n\t}, [ alt, caption, id, linkDestination, sizeSlug, url ] );\n\n\t// Reads the cached attachment record. The `attachment` postType entity\n\t// fetches with `context: 'edit'` by default, so `getEditedEntityRecord`\n\t// returns the edit-context record — carrying `caption` as `{ raw }` and a\n\t// usable `alt_text` — without us specifying a context. It is resolver-\n\t// backed, so on a cold cache this also kicks off the fetch and returns a\n\t// falsy value synchronously; that resolution shares its cache key with the\n\t// `resolveAttachmentRecord` call below (both keyed on the no-query\n\t// `getEntityRecord`), so the two dedupe into a single request.\n\tconst getCachedAttachmentRecord = useCallback(\n\t\t( attachmentId ) =>\n\t\t\tregistry\n\t\t\t\t.select( coreStore )\n\t\t\t\t.getEditedEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'attachment',\n\t\t\t\t\tattachmentId\n\t\t\t\t),\n\t\t[ registry ]\n\t);\n\n\tconst resolveAttachmentRecord = useCallback(\n\t\tasync ( attachmentId ) => {\n\t\t\tconst resolveSelect = registry.resolveSelect( coreStore );\n\n\t\t\ttry {\n\t\t\t\treturn await resolveSelect.getEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'attachment',\n\t\t\t\t\tattachmentId\n\t\t\t\t);\n\t\t\t} catch {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t},\n\t\t[ registry ]\n\t);\n\n\tconst resolveFreshAttachmentRecord = useCallback(\n\t\tasync ( attachmentId ) => {\n\t\t\t// Invalidate the cached resolution so resolveAttachmentRecord\n\t\t\t// re-fetches the server state that reflects the media editor's\n\t\t\t// saved changes.\n\t\t\tconst { invalidateResolution } = registry.dispatch( coreStore );\n\n\t\t\tinvalidateResolution( 'getEntityRecord', [\n\t\t\t\t'postType',\n\t\t\t\t'attachment',\n\t\t\t\tattachmentId,\n\t\t\t] );\n\t\t\treturn resolveAttachmentRecord( attachmentId );\n\t\t},\n\t\t[ registry, resolveAttachmentRecord ]\n\t);\n\n\tconst handleMediaUpdate = useCallback(\n\t\tasync ( { id: newId, url: newUrl } ) => {\n\t\t\tif ( typeof newId !== 'number' ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Capture and clear the baseline so a rapid second save doesn't\n\t\t\t// reuse a stale snapshot.\n\t\t\tconst originalAttachment = mediaEditorMetadataBaselineRef.current;\n\t\t\tmediaEditorMetadataBaselineRef.current = undefined;\n\t\t\t// Likewise the metadata the last save overwrote: only the update\n\t\t\t// straight after that save, its Undo, may restore it.\n\t\t\tconst undoMetadata = mediaEditorUndoMetadataRef.current;\n\t\t\tmediaEditorUndoMetadataRef.current = undefined;\n\t\t\tconst syncRequest = ++mediaEditorMetadataSyncRequestRef.current;\n\t\t\tconst nextAttributes = {};\n\n\t\t\tconst currentBlockAttributes = blockAttributesRef.current;\n\t\t\tconst isNewAttachment = newId !== currentBlockAttributes.id;\n\n\t\t\tif ( isNewAttachment ) {\n\t\t\t\tnextAttributes.id = newId;\n\t\t\t\tnextAttributes.url = newUrl ?? currentBlockAttributes.url;\n\t\t\t\tif ( nextAttributes.url !== currentBlockAttributes.url ) {\n\t\t\t\t\t// The block is about to point at a freshly generated file\n\t\t\t\t\t// the browser hasn't loaded yet; let the caller show a\n\t\t\t\t\t// loading state until its <img> fires load/error. Raising\n\t\t\t\t\t// it here, before anything is awaited, keeps the rest of\n\t\t\t\t\t// this update behind that loading state: the attributes\n\t\t\t\t\t// land in a single `setAttributes` at the end, so the\n\t\t\t\t\t// image never renders against half-updated settings.\n\t\t\t\t\tonUrlChange?.( nextAttributes.url );\n\t\t\t\t}\n\t\t\t\tblockAttributesRef.current = {\n\t\t\t\t\t...blockAttributesRef.current,\n\t\t\t\t\tid: nextAttributes.id,\n\t\t\t\t\turl: nextAttributes.url,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif ( originalAttachment || isNewAttachment ) {\n\t\t\t\t// Fetch fresh server state so this reflects what the media\n\t\t\t\t// editor actually saved, not a potentially stale cache.\n\t\t\t\tconst resolvedAttachment =\n\t\t\t\t\tawait resolveFreshAttachmentRecord( newId );\n\n\t\t\t\t// A newer update started while we were awaiting; discard\n\t\t\t\t// this one.\n\t\t\t\tif (\n\t\t\t\t\tsyncRequest !== mediaEditorMetadataSyncRequestRef.current\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// A failed refetch returns nothing, which would leave the\n\t\t\t\t// block pointing at the new file while its size and link\n\t\t\t\t// still describe the old one. The record the media editor\n\t\t\t\t// received when it saved is already in the store, so fall\n\t\t\t\t// back to that rather than half-updating the block.\n\t\t\t\tconst attachmentRecord =\n\t\t\t\t\tresolvedAttachment ?? getCachedAttachmentRecord( newId );\n\n\t\t\t\tconst latestBlockAttributes = blockAttributesRef.current;\n\n\t\t\t\t// Sync alt text and caption back to the block only when\n\t\t\t\t// they were changed in the media editor. Fields the user\n\t\t\t\t// has independently customised on the block (i.e. values\n\t\t\t\t// that don't match the pre-session attachment metadata)\n\t\t\t\t// are left untouched. Without a baseline there's no way to\n\t\t\t\t// tell the two apart, so nothing is synced.\n\t\t\t\tif ( originalAttachment ) {\n\t\t\t\t\tconst resolvedMetadataAttributes =\n\t\t\t\t\t\tgetSyncedImageBlockAttributes(\n\t\t\t\t\t\t\tlatestBlockAttributes,\n\t\t\t\t\t\t\toriginalAttachment,\n\t\t\t\t\t\t\tattachmentRecord\n\t\t\t\t\t\t);\n\n\t\t\t\t\tif ( Object.keys( resolvedMetadataAttributes ).length ) {\n\t\t\t\t\t\tObject.assign(\n\t\t\t\t\t\t\tnextAttributes,\n\t\t\t\t\t\t\tresolvedMetadataAttributes\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\t// Only a save to a new attachment offers an Undo, so\n\t\t\t\t\t\t// only then keep the values being overwritten.\n\t\t\t\t\t\tif ( isNewAttachment ) {\n\t\t\t\t\t\t\tmediaEditorUndoMetadataRef.current = {\n\t\t\t\t\t\t\t\tid: currentBlockAttributes.id,\n\t\t\t\t\t\t\t\tattributes: Object.fromEntries(\n\t\t\t\t\t\t\t\t\tObject.keys(\n\t\t\t\t\t\t\t\t\t\tresolvedMetadataAttributes\n\t\t\t\t\t\t\t\t\t).map( ( key ) => [\n\t\t\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t\t\t\tlatestBlockAttributes[ key ],\n\t\t\t\t\t\t\t\t\t] )\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif ( isNewAttachment ) {\n\t\t\t\t\tconst derivedAttributes =\n\t\t\t\t\t\tgetNewAttachmentImageBlockAttributes(\n\t\t\t\t\t\t\tlatestBlockAttributes,\n\t\t\t\t\t\t\tattachmentRecord\n\t\t\t\t\t\t);\n\n\t\t\t\t\tif ( derivedAttributes ) {\n\t\t\t\t\t\tObject.assign( nextAttributes, derivedAttributes );\n\n\t\t\t\t\t\t// The URL announced before the resolve was the\n\t\t\t\t\t\t// full-size file the media editor reported, and\n\t\t\t\t\t\t// deriving the selected size can change it.\n\t\t\t\t\t\t// Re-announce so the pending swap names the file\n\t\t\t\t\t\t// that actually lands: an update that is undone or\n\t\t\t\t\t\t// superseded never changes the <img> src, and the\n\t\t\t\t\t\t// block then clears its loading state by matching\n\t\t\t\t\t\t// the pending URL against the rendered one.\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tderivedAttributes.url &&\n\t\t\t\t\t\t\tderivedAttributes.url !== latestBlockAttributes.url\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tonUrlChange?.( derivedAttributes.url );\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// The media editor's Undo: the block is going back to the\n\t\t\t// attachment the last save moved it away from, so put back the\n\t\t\t// alt text and caption that save overwrote.\n\t\t\tif ( undoMetadata?.id === newId ) {\n\t\t\t\tObject.assign( nextAttributes, undoMetadata.attributes );\n\t\t\t}\n\n\t\t\tif ( Object.keys( nextAttributes ).length ) {\n\t\t\t\tblockAttributesRef.current = {\n\t\t\t\t\t...blockAttributesRef.current,\n\t\t\t\t\t...nextAttributes,\n\t\t\t\t};\n\t\t\t\tsetAttributes( nextAttributes );\n\t\t\t}\n\t\t},\n\t\t[\n\t\t\tgetCachedAttachmentRecord,\n\t\t\tonUrlChange,\n\t\t\tresolveFreshAttachmentRecord,\n\t\t\tsetAttributes,\n\t\t]\n\t);\n\n\tconst openImageMediaEditorModal = useCallback( async () => {\n\t\tif ( ! id || ! openMediaEditorModal ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// A new session starts. Drop any metadata kept for the last save's\n\t\t// Undo, so a save in this session that returns the block to that same\n\t\t// attachment isn't mistaken for it.\n\t\tmediaEditorUndoMetadataRef.current = undefined;\n\n\t\t// Snapshot the attachment's current metadata before the user makes\n\t\t// any changes so handleMediaUpdate can compare against it later. Use\n\t\t// the cached record when it's already present; only resolve when\n\t\t// nothing is cached yet, then fall back to a minimal object derived\n\t\t// from the block's own attributes.\n\t\tconst cachedAttachmentRecord = getCachedAttachmentRecord( id );\n\t\tconst fallbackAttachmentRecord =\n\t\t\tgetAttachmentFallbackForEmptyBlockMetadata(\n\t\t\t\tblockAttributesRef.current\n\t\t\t);\n\t\tconst resolvedAttachmentRecord = hasKnownAttachmentMetadata(\n\t\t\tcachedAttachmentRecord\n\t\t)\n\t\t\t? undefined\n\t\t\t: await resolveAttachmentRecord( id );\n\n\t\tmediaEditorMetadataBaselineRef.current =\n\t\t\tresolvedAttachmentRecord ||\n\t\t\t( hasKnownAttachmentMetadata( cachedAttachmentRecord )\n\t\t\t\t? cachedAttachmentRecord\n\t\t\t\t: fallbackAttachmentRecord ) ||\n\t\t\tcachedAttachmentRecord;\n\n\t\topenMediaEditorModal( {\n\t\t\tid,\n\t\t\tonUpdate: handleMediaUpdate,\n\t\t\tonClose,\n\t\t} );\n\t}, [\n\t\tgetCachedAttachmentRecord,\n\t\thandleMediaUpdate,\n\t\tid,\n\t\tonClose,\n\t\topenMediaEditorModal,\n\t\tresolveAttachmentRecord,\n\t] );\n\n\treturn id && openMediaEditorModal ? openImageMediaEditorModal : undefined;\n}\n"],
5
- "mappings": ";AAAA,SAAS,SAAS,iBAAiB;AACnC;AAAA,EACC,eAAe;AAAA,EACf,SAAS;AAAA,OACH;AACP,SAAS,uBAAuB,iBAAiB;AACjD,SAAS,aAAa,iBAAiB;AACvC,SAAS,aAAa,WAAW,cAAc;AAC/C,SAAS,cAAc;AACvB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAEP,SAAS,2BAA4B,SAAU;AAC9C,MAAK,OAAO,YAAY,UAAW;AAClC,WAAO;AAAA,EACR;AAEA,QAAM,cAAc,UAAW,OAAQ,EAAE,KAAK;AAE9C,MAAK,CAAE,aAAc;AACpB,WAAO;AAAA,EACR;AAEA,SAAO,QAAQ,QAAS,OAAO,MAAO;AACvC;AAEA,SAAS,qBAAsB,YAAa;AAC3C,QAAM,UAAU,YAAY;AAE5B,MAAK,OAAO,YAAY,UAAW;AAClC,WAAO,2BAA4B,OAAQ;AAAA,EAC5C;AAEA,MACC,WACA,OAAO,YAAY,YACnB,OAAO,OAAQ,SAAS,KAAM,GAC7B;AACD,WAAO,2BAA4B,QAAQ,GAAI;AAAA,EAChD;AAEA,SAAO;AACR;AAEO,SAAS,oCAAqC,YAAa;AACjE,SAAO;AAAA,IACN,KACC,OAAO,YAAY,aAAa,WAC7B,WAAW,WACX,YAAY,OAAO;AAAA,IACvB,SAAS,qBAAsB,UAAW;AAAA,EAC3C;AACD;AAEA,SAAS,2BAA4B,OAAQ;AAC5C,SAAO,SAAS;AACjB;AAEO,SAAS,8BACf,mBACA,oBACA,mBACC;AACD,MAAK,CAAE,sBAAsB,CAAE,mBAAoB;AAClD,WAAO,CAAC;AAAA,EACT;AAEA,QAAM,mBACL,oCAAqC,kBAAmB;AACzD,QAAM,kBACL,oCAAqC,iBAAkB;AACxD,Q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AA,EACD;AAEA,QAAM,4BAA4B,YAAa,YAAY;AAC1D,QAAK,CAAE,MAAM,CAAE,sBAAuB;AACrC;AAAA,IACD;AAKA,+BAA2B,UAAU;AAOrC,UAAM,yBAAyB,0BAA2B,EAAG;AAC7D,UAAM,2BACL;AAAA,MACC,mBAAmB;AAAA,IACpB;AACD,UAAM,2BAA2B;AAAA,MAChC;AAAA,IACD,IACG,SACA,MAAM,wBAAyB,EAAG;AAErC,mCAA+B,UAC9B,6BACE,2BAA4B,sBAAuB,IAClD,yBACA,6BACH;AAED,yBAAsB;AAAA,MACrB;AAAA,MACA,UAAU;AAAA,MACV;AAAA,IACD,CAAE;AAAA,EACH,GAAG;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,CAAE;AAEF,SAAO,MAAM,uBAAuB,4BAA4B;AACjE;",
4
+ "sourcesContent": ["import { store as coreStore } from '@wordpress/core-data';\nimport {\n\tprivateApis as blockEditorPrivateApis,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\nimport { useRegistry, useSelect } from '@wordpress/data';\nimport { useCallback, useEffect, useRef } from '@wordpress/element';\nimport { unlock } from '../lock-unlock';\nimport {\n\tDEFAULT_MEDIA_SIZE_SLUG,\n\tLINK_DESTINATION_ATTACHMENT,\n\tLINK_DESTINATION_MEDIA,\n} from './constants';\n\nfunction normalizeImageBlockCaption( caption ) {\n\tif ( typeof caption !== 'string' ) {\n\t\treturn '';\n\t}\n\n\tconst textContent = stripHTML( caption ).trim();\n\n\tif ( ! textContent ) {\n\t\treturn '';\n\t}\n\n\treturn caption.replace( /\\n/g, '<br>' );\n}\n\nfunction getAttachmentCaption( attachment ) {\n\tconst caption = attachment?.caption;\n\n\tif ( typeof caption === 'string' ) {\n\t\treturn normalizeImageBlockCaption( caption );\n\t}\n\n\tif (\n\t\tcaption &&\n\t\ttypeof caption === 'object' &&\n\t\tObject.hasOwn( caption, 'raw' )\n\t) {\n\t\treturn normalizeImageBlockCaption( caption.raw );\n\t}\n\n\treturn undefined;\n}\n\nexport function getImageBlockMetadataFromAttachment( attachment ) {\n\treturn {\n\t\talt:\n\t\t\ttypeof attachment?.alt_text === 'string'\n\t\t\t\t? attachment.alt_text\n\t\t\t\t: attachment?.alt || '',\n\t\tcaption: getAttachmentCaption( attachment ),\n\t};\n}\n\nfunction normalizeMetadataAttribute( value ) {\n\treturn value || '';\n}\n\nexport function getSyncedImageBlockAttributes(\n\tcurrentAttributes,\n\toriginalAttachment,\n\tupdatedAttachment\n) {\n\tif ( ! originalAttachment || ! updatedAttachment ) {\n\t\treturn {};\n\t}\n\n\tconst originalMetadata =\n\t\tgetImageBlockMetadataFromAttachment( originalAttachment );\n\tconst updatedMetadata =\n\t\tgetImageBlockMetadataFromAttachment( updatedAttachment );\n\tconst syncedAttributes = {};\n\n\tconst normalizedCurrentAlt = normalizeMetadataAttribute(\n\t\tcurrentAttributes.alt\n\t);\n\tif (\n\t\toriginalMetadata.alt !== updatedMetadata.alt &&\n\t\t( normalizedCurrentAlt === originalMetadata.alt ||\n\t\t\t! normalizedCurrentAlt )\n\t) {\n\t\tsyncedAttributes.alt = updatedMetadata.alt;\n\t}\n\n\tconst normalizedCurrentCaption = normalizeMetadataAttribute(\n\t\tcurrentAttributes.caption\n\t);\n\tif (\n\t\toriginalMetadata.caption !== undefined &&\n\t\tupdatedMetadata.caption !== undefined &&\n\t\toriginalMetadata.caption !== updatedMetadata.caption &&\n\t\t( normalizedCurrentCaption === originalMetadata.caption ||\n\t\t\t! normalizedCurrentCaption )\n\t) {\n\t\tsyncedAttributes.caption = updatedMetadata.caption || undefined;\n\t}\n\n\treturn syncedAttributes;\n}\n\n/**\n * Resolves the attributes needed to keep the selected image size on a new\n * attachment.\n *\n * WordPress skips generating a sub-size larger than the file itself, so the\n * selected size may not exist on the edited image; fall back to full when it\n * doesn't.\n *\n * @param {string|undefined} sizeSlug The block's currently selected size.\n * @param {Object} attachment The new attachment record.\n *\n * @return {Object|undefined} Attributes to apply, if any.\n */\nfunction getNewAttachmentSizeAttributes( sizeSlug, attachment ) {\n\tconst sizes = attachment.media_details?.sizes;\n\n\tif ( ! sizeSlug || sizeSlug === DEFAULT_MEDIA_SIZE_SLUG || ! sizes ) {\n\t\treturn undefined;\n\t}\n\n\tconst sizeUrl = sizes[ sizeSlug ]?.source_url;\n\n\tif ( sizeUrl ) {\n\t\treturn { url: sizeUrl };\n\t}\n\n\tconst fullUrl = attachment.source_url ?? sizes.full?.source_url;\n\n\treturn fullUrl\n\t\t? { url: fullUrl, sizeSlug: DEFAULT_MEDIA_SIZE_SLUG }\n\t\t: undefined;\n}\n\n/**\n * Resolves the link attributes needed to keep the block's link pointing at the\n * new attachment.\n *\n * Only the destinations derived from the attachment follow the edited image. A\n * `custom` link is the user's own URL and a `none` link has nothing to point\n * at, so both are left alone. When the record doesn't carry the field, the\n * existing link is kept rather than cleared.\n *\n * @param {string|undefined} linkDestination The block's link destination.\n * @param {Object} attachment The new attachment record.\n *\n * @return {Object|undefined} Attributes to apply, if any.\n */\nfunction getNewAttachmentLinkAttributes( linkDestination, attachment ) {\n\t// Media file links point at the full-size file, independently of the size\n\t// the block renders.\n\tif ( linkDestination === LINK_DESTINATION_MEDIA ) {\n\t\treturn attachment.source_url\n\t\t\t? { href: attachment.source_url }\n\t\t\t: undefined;\n\t}\n\n\tif ( linkDestination === LINK_DESTINATION_ATTACHMENT ) {\n\t\treturn attachment.link ? { href: attachment.link } : undefined;\n\t}\n\n\treturn undefined;\n}\n\n/**\n * Resolves the block attributes that are derived from the attachment, for an\n * edit that saved to a different one.\n *\n * Editing media (crop, rotate, flip) creates a new attachment with its own\n * generated sub-sizes and its own attachment page, and the media editor\n * reports the full-size file. Without re-deriving these, the size control\n * keeps reporting e.g. \"Medium\" while the block renders the full-size image,\n * and a \"Media file\" or \"Attachment page\" link still points at the image as it\n * was before the edit. Everything else the user set on the block — dimensions,\n * lightbox, title, custom links — is left untouched.\n *\n * @param {Object} blockAttributes The block's current attributes.\n * @param {Object|undefined} attachment The new attachment record.\n *\n * @return {Object|undefined} Attributes to apply, or undefined when the\n * attachment record isn't known yet.\n */\nexport function getNewAttachmentImageBlockAttributes(\n\tblockAttributes,\n\tattachment\n) {\n\tif ( ! attachment ) {\n\t\treturn undefined;\n\t}\n\n\treturn {\n\t\t...getNewAttachmentSizeAttributes(\n\t\t\tblockAttributes.sizeSlug,\n\t\t\tattachment\n\t\t),\n\t\t...getNewAttachmentLinkAttributes(\n\t\t\tblockAttributes.linkDestination,\n\t\t\tattachment\n\t\t),\n\t};\n}\n\nconst { openMediaEditorModalKey } = unlock( blockEditorPrivateApis );\n\nfunction getAttachmentFallbackForEmptyBlockMetadata( { alt, caption } ) {\n\tconst attachment = {};\n\n\tif ( ! alt ) {\n\t\tattachment.alt_text = '';\n\t}\n\n\tif ( ! caption?.toString() ) {\n\t\tattachment.caption = '';\n\t}\n\n\treturn Object.keys( attachment ).length ? attachment : undefined;\n}\n\nfunction hasKnownAttachmentMetadata( attachment ) {\n\tif ( ! attachment ) {\n\t\treturn false;\n\t}\n\n\tconst hasKnownAlt =\n\t\ttypeof attachment.alt_text === 'string' ||\n\t\ttypeof attachment.alt === 'string';\n\tconst hasKnownCaption =\n\t\tgetImageBlockMetadataFromAttachment( attachment ).caption !== undefined;\n\n\treturn hasKnownAlt && hasKnownCaption;\n}\n\nexport function useOpenImageMediaEditorModal( {\n\tattributes,\n\tsetAttributes,\n\tonClose,\n\tonUrlChange,\n} ) {\n\t// Keep this hook private to the Image block and pass the block attributes\n\t// object so the callsite stays compact. Destructure only the attributes\n\t// the update needs to read — those synced from the attachment's metadata,\n\t// and those derived from which attachment the block points at; add more\n\t// here if the sync policy grows.\n\tconst { id, url, alt, caption, sizeSlug, linkDestination, href } =\n\t\tattributes;\n\tconst registry = useRegistry();\n\tconst openMediaEditorModal = useSelect(\n\t\t( select ) =>\n\t\t\tselect( blockEditorStore ).getSettings()[ openMediaEditorModalKey ],\n\t\t[]\n\t);\n\t// Track the block's current attachment and metadata in a ref so\n\t// handleMediaUpdate can read the latest values without being listed as\n\t// dependencies (which would recreate the callback and re-register the\n\t// onUpdate handler on every block change while the modal is open).\n\tconst blockAttributesRef = useRef( {\n\t\tid,\n\t\turl,\n\t\talt,\n\t\tcaption: caption?.toString(),\n\t\tsizeSlug,\n\t\tlinkDestination,\n\t\thref,\n\t} );\n\t// Snapshot of the attachment's metadata taken just before the modal opens,\n\t// used as the baseline for detecting what changed during the editing session.\n\tconst mediaEditorMetadataBaselineRef = useRef();\n\t// Incremented on every handleMediaUpdate call; stale async continuations\n\t// check against this to bail out if a newer update has since started.\n\tconst mediaEditorMetadataSyncRequestRef = useRef( 0 );\n\n\tuseEffect( () => {\n\t\tblockAttributesRef.current = {\n\t\t\tid,\n\t\t\turl,\n\t\t\talt,\n\t\t\tcaption: caption?.toString(),\n\t\t\tsizeSlug,\n\t\t\tlinkDestination,\n\t\t\thref,\n\t\t};\n\t}, [ alt, caption, href, id, linkDestination, sizeSlug, url ] );\n\n\t// Reads the cached attachment record. The `attachment` postType entity\n\t// fetches with `context: 'edit'` by default, so `getEditedEntityRecord`\n\t// returns the edit-context record — carrying `caption` as `{ raw }` and a\n\t// usable `alt_text` — without us specifying a context. It is resolver-\n\t// backed, so on a cold cache this also kicks off the fetch and returns a\n\t// falsy value synchronously; that resolution shares its cache key with the\n\t// `resolveAttachmentRecord` call below (both keyed on the no-query\n\t// `getEntityRecord`), so the two dedupe into a single request.\n\tconst getCachedAttachmentRecord = useCallback(\n\t\t( attachmentId ) =>\n\t\t\tregistry\n\t\t\t\t.select( coreStore )\n\t\t\t\t.getEditedEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'attachment',\n\t\t\t\t\tattachmentId\n\t\t\t\t),\n\t\t[ registry ]\n\t);\n\n\tconst resolveAttachmentRecord = useCallback(\n\t\tasync ( attachmentId ) => {\n\t\t\tconst resolveSelect = registry.resolveSelect( coreStore );\n\n\t\t\ttry {\n\t\t\t\treturn await resolveSelect.getEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'attachment',\n\t\t\t\t\tattachmentId\n\t\t\t\t);\n\t\t\t} catch {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t},\n\t\t[ registry ]\n\t);\n\n\tconst resolveFreshAttachmentRecord = useCallback(\n\t\tasync ( attachmentId ) => {\n\t\t\t// Invalidate the cached resolution so resolveAttachmentRecord\n\t\t\t// re-fetches the server state that reflects the media editor's\n\t\t\t// saved changes.\n\t\t\tconst { invalidateResolution } = registry.dispatch( coreStore );\n\n\t\t\tinvalidateResolution( 'getEntityRecord', [\n\t\t\t\t'postType',\n\t\t\t\t'attachment',\n\t\t\t\tattachmentId,\n\t\t\t] );\n\t\t\treturn resolveAttachmentRecord( attachmentId );\n\t\t},\n\t\t[ registry, resolveAttachmentRecord ]\n\t);\n\n\tconst handleMediaUpdate = useCallback(\n\t\tasync ( { id: newId, url: newUrl }, undoState ) => {\n\t\t\tif ( typeof newId !== 'number' ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Capture and clear the baseline so a rapid second save doesn't\n\t\t\t// reuse a stale snapshot.\n\t\t\tconst originalAttachment = mediaEditorMetadataBaselineRef.current;\n\t\t\tmediaEditorMetadataBaselineRef.current = undefined;\n\t\t\tconst syncRequest = ++mediaEditorMetadataSyncRequestRef.current;\n\t\t\tconst nextAttributes = {};\n\n\t\t\tconst currentBlockAttributes = blockAttributesRef.current;\n\t\t\tconst isNewAttachment = newId !== currentBlockAttributes.id;\n\n\t\t\tif ( isNewAttachment ) {\n\t\t\t\t// Capture the block's selected-size URL, not the attachment's\n\t\t\t\t// full-size URL supplied by the modal's fallback Undo.\n\t\t\t\tundoState.undoAttributes.id = currentBlockAttributes.id;\n\t\t\t\tundoState.undoAttributes.url = currentBlockAttributes.url;\n\t\t\t\tnextAttributes.id = newId;\n\t\t\t\tnextAttributes.url = newUrl ?? currentBlockAttributes.url;\n\t\t\t\tif ( nextAttributes.url !== currentBlockAttributes.url ) {\n\t\t\t\t\t// The block is about to point at a freshly generated file\n\t\t\t\t\t// the browser hasn't loaded yet; let the caller show a\n\t\t\t\t\t// loading state until its <img> fires load/error. Raising\n\t\t\t\t\t// it here, before anything is awaited, keeps the rest of\n\t\t\t\t\t// this update behind that loading state: the attributes\n\t\t\t\t\t// land in a single `setAttributes` at the end, so the\n\t\t\t\t\t// image never renders against half-updated settings.\n\t\t\t\t\tonUrlChange?.( nextAttributes.url );\n\t\t\t\t}\n\t\t\t\tblockAttributesRef.current = {\n\t\t\t\t\t...blockAttributesRef.current,\n\t\t\t\t\tid: nextAttributes.id,\n\t\t\t\t\turl: nextAttributes.url,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif ( originalAttachment || isNewAttachment ) {\n\t\t\t\t// Fetch fresh server state so this reflects what the media\n\t\t\t\t// editor actually saved, not a potentially stale cache.\n\t\t\t\tconst resolvedAttachment =\n\t\t\t\t\tawait resolveFreshAttachmentRecord( newId );\n\n\t\t\t\t// A newer update started while we were awaiting; discard\n\t\t\t\t// this one.\n\t\t\t\tif (\n\t\t\t\t\tundoState.isUndone ||\n\t\t\t\t\tsyncRequest !== mediaEditorMetadataSyncRequestRef.current\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// A failed refetch returns nothing, which would leave the\n\t\t\t\t// block pointing at the new file while its size and link\n\t\t\t\t// still describe the old one. The record the media editor\n\t\t\t\t// received when it saved is already in the store, so fall\n\t\t\t\t// back to that rather than half-updating the block.\n\t\t\t\tconst attachmentRecord =\n\t\t\t\t\tresolvedAttachment ?? getCachedAttachmentRecord( newId );\n\n\t\t\t\tconst latestBlockAttributes = blockAttributesRef.current;\n\n\t\t\t\t// Sync alt text and caption back to the block only when\n\t\t\t\t// they were changed in the media editor. Fields the user\n\t\t\t\t// has independently customised on the block (i.e. values\n\t\t\t\t// that don't match the pre-session attachment metadata)\n\t\t\t\t// are left untouched. Without a baseline there's no way to\n\t\t\t\t// tell the two apart, so nothing is synced.\n\t\t\t\tif ( originalAttachment ) {\n\t\t\t\t\tconst resolvedMetadataAttributes =\n\t\t\t\t\t\tgetSyncedImageBlockAttributes(\n\t\t\t\t\t\t\tlatestBlockAttributes,\n\t\t\t\t\t\t\toriginalAttachment,\n\t\t\t\t\t\t\tattachmentRecord\n\t\t\t\t\t\t);\n\n\t\t\t\t\tif ( Object.keys( resolvedMetadataAttributes ).length ) {\n\t\t\t\t\t\tObject.assign(\n\t\t\t\t\t\t\tnextAttributes,\n\t\t\t\t\t\t\tresolvedMetadataAttributes\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif ( isNewAttachment ) {\n\t\t\t\t\tconst derivedAttributes =\n\t\t\t\t\t\tgetNewAttachmentImageBlockAttributes(\n\t\t\t\t\t\t\tlatestBlockAttributes,\n\t\t\t\t\t\t\tattachmentRecord\n\t\t\t\t\t\t);\n\n\t\t\t\t\tif ( derivedAttributes ) {\n\t\t\t\t\t\tObject.assign( nextAttributes, derivedAttributes );\n\n\t\t\t\t\t\t// The URL announced before the resolve was the\n\t\t\t\t\t\t// full-size file the media editor reported, and\n\t\t\t\t\t\t// deriving the selected size can change it.\n\t\t\t\t\t\t// Re-announce so the pending swap names the file\n\t\t\t\t\t\t// that actually lands: an update that is undone or\n\t\t\t\t\t\t// superseded never changes the <img> src, and the\n\t\t\t\t\t\t// block then clears its loading state by matching\n\t\t\t\t\t\t// the pending URL against the rendered one.\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tderivedAttributes.url &&\n\t\t\t\t\t\t\tderivedAttributes.url !== latestBlockAttributes.url\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tonUrlChange?.( derivedAttributes.url );\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( Object.keys( nextAttributes ).length ) {\n\t\t\t\t// Only restore values this save changed. Block-specific\n\t\t\t\t// metadata and unrelated edits must not be overwritten.\n\t\t\t\tfor ( const key of Object.keys( nextAttributes ) ) {\n\t\t\t\t\tif ( ! Object.hasOwn( undoState.undoAttributes, key ) ) {\n\t\t\t\t\t\tundoState.undoAttributes[ key ] =\n\t\t\t\t\t\t\tblockAttributesRef.current[ key ];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tblockAttributesRef.current = {\n\t\t\t\t\t...blockAttributesRef.current,\n\t\t\t\t\t...nextAttributes,\n\t\t\t\t};\n\t\t\t\tsetAttributes( nextAttributes );\n\t\t\t}\n\t\t},\n\t\t[\n\t\t\tgetCachedAttachmentRecord,\n\t\t\tonUrlChange,\n\t\t\tresolveFreshAttachmentRecord,\n\t\t\tsetAttributes,\n\t\t]\n\t);\n\n\tconst openImageMediaEditorModal = useCallback( async () => {\n\t\tif ( ! id || ! openMediaEditorModal ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Snapshot the attachment's current metadata before the user makes\n\t\t// any changes so handleMediaUpdate can compare against it later. Use\n\t\t// the cached record when it's already present; only resolve when\n\t\t// nothing is cached yet, then fall back to a minimal object derived\n\t\t// from the block's own attributes.\n\t\tconst cachedAttachmentRecord = getCachedAttachmentRecord( id );\n\t\tconst fallbackAttachmentRecord =\n\t\t\tgetAttachmentFallbackForEmptyBlockMetadata(\n\t\t\t\tblockAttributesRef.current\n\t\t\t);\n\t\tconst resolvedAttachmentRecord = hasKnownAttachmentMetadata(\n\t\t\tcachedAttachmentRecord\n\t\t)\n\t\t\t? undefined\n\t\t\t: await resolveAttachmentRecord( id );\n\n\t\tmediaEditorMetadataBaselineRef.current =\n\t\t\tresolvedAttachmentRecord ||\n\t\t\t( hasKnownAttachmentMetadata( cachedAttachmentRecord )\n\t\t\t\t? cachedAttachmentRecord\n\t\t\t\t: fallbackAttachmentRecord ) ||\n\t\t\tcachedAttachmentRecord;\n\n\t\t// Each opening owns its Undo snapshot, so a later opening cannot\n\t\t// replace the values captured by an earlier snackbar.\n\t\tconst undoState = { undoAttributes: {}, isUndone: false };\n\t\topenMediaEditorModal( {\n\t\t\tid,\n\t\t\tonUpdate: ( updated ) => handleMediaUpdate( updated, undoState ),\n\t\t\tonUndo: () => {\n\t\t\t\tundoState.isUndone = true;\n\t\t\t\tconst { undoAttributes } = undoState;\n\t\t\t\tif ( Object.hasOwn( undoAttributes, 'url' ) ) {\n\t\t\t\t\tonUrlChange?.( undoAttributes.url );\n\t\t\t\t}\n\t\t\t\tblockAttributesRef.current = {\n\t\t\t\t\t...blockAttributesRef.current,\n\t\t\t\t\t...undoAttributes,\n\t\t\t\t};\n\t\t\t\tsetAttributes( undoAttributes );\n\t\t\t},\n\t\t\tonClose,\n\t\t} );\n\t}, [\n\t\tgetCachedAttachmentRecord,\n\t\thandleMediaUpdate,\n\t\tid,\n\t\tonClose,\n\t\tonUrlChange,\n\t\topenMediaEditorModal,\n\t\tresolveAttachmentRecord,\n\t\tsetAttributes,\n\t] );\n\n\treturn id && openMediaEditorModal ? openImageMediaEditorModal : undefined;\n}\n"],
5
+ "mappings": ";AAAA,SAAS,SAAS,iBAAiB;AACnC;AAAA,EACC,eAAe;AAAA,EACf,SAAS;AAAA,OACH;AACP,SAAS,uBAAuB,iBAAiB;AACjD,SAAS,aAAa,iBAAiB;AACvC,SAAS,aAAa,WAAW,cAAc;AAC/C,SAAS,cAAc;AACvB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAEP,SAAS,2BAA4B,SAAU;AAC9C,MAAK,OAAO,YAAY,UAAW;AAClC,WAAO;AAAA,EACR;AAEA,QAAM,cAAc,UAAW,OAAQ,EAAE,KAAK;AAE9C,MAAK,CAAE,aAAc;AACpB,WAAO;AAAA,EACR;AAEA,SAAO,QAAQ,QAAS,OAAO,MAAO;AACvC;AAEA,SAAS,qBAAsB,YAAa;AAC3C,QAAM,UAAU,YAAY;AAE5B,MAAK,OAAO,YAAY,UAAW;AAClC,WAAO,2BAA4B,OAAQ;AAAA,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,IACA;AAAA,IACA;AAAA,EACD,CAAE;AAEF,SAAO,MAAM,uBAAuB,4BAA4B;AACjE;",
6
6
  "names": []
7
7
  }
@@ -15,6 +15,7 @@ var touchStartEvent = {
15
15
  startY: 0,
16
16
  startTime: 0
17
17
  };
18
+ var inertElements = [];
18
19
  var focusableSelectors = [
19
20
  ".wp-lightbox-close-button",
20
21
  ".wp-lightbox-navigation-button"
@@ -286,7 +287,7 @@ var { state, actions, callbacks } = store(
286
287
  } = state.selectedImage.imageRef;
287
288
  let { x: screenPosX, y: screenPosY } = state.selectedImage.imageRef.getBoundingClientRect();
288
289
  const naturalRatio = naturalWidth / naturalHeight;
289
- let originalRatio = originalWidth / originalHeight;
290
+ const originalRatio = originalWidth / originalHeight;
290
291
  if (state.selectedImage.scaleAttr === "contain") {
291
292
  if (naturalRatio > originalRatio) {
292
293
  const heightWithoutSpace = originalWidth / naturalRatio;
@@ -298,47 +299,15 @@ var { state, actions, callbacks } = store(
298
299
  originalWidth = widthWithoutSpace;
299
300
  }
300
301
  }
301
- originalRatio = originalWidth / originalHeight;
302
- let imgMaxWidth = parseFloat(
302
+ const imgMaxWidth = parseFloat(
303
303
  state.selectedImage.targetWidth && state.selectedImage.targetWidth !== "none" ? state.selectedImage.targetWidth : naturalWidth
304
304
  );
305
- let imgMaxHeight = parseFloat(
305
+ const imgMaxHeight = parseFloat(
306
306
  state.selectedImage.targetHeight && state.selectedImage.targetHeight !== "none" ? state.selectedImage.targetHeight : naturalHeight
307
307
  );
308
- let imgRatio = imgMaxWidth / imgMaxHeight;
309
- let containerMaxWidth = imgMaxWidth;
310
- let containerMaxHeight = imgMaxHeight;
308
+ const fullSizeRatio = imgMaxWidth / imgMaxHeight;
311
309
  let containerWidth = imgMaxWidth;
312
310
  let containerHeight = imgMaxHeight;
313
- if (naturalRatio.toFixed(2) !== imgRatio.toFixed(2)) {
314
- if (naturalRatio > imgRatio) {
315
- const reducedHeight = imgMaxWidth / naturalRatio;
316
- if (imgMaxHeight - reducedHeight > imgMaxWidth) {
317
- imgMaxHeight = reducedHeight;
318
- imgMaxWidth = reducedHeight * naturalRatio;
319
- } else {
320
- imgMaxHeight = imgMaxWidth / naturalRatio;
321
- }
322
- } else {
323
- const reducedWidth = imgMaxHeight * naturalRatio;
324
- if (imgMaxWidth - reducedWidth > imgMaxHeight) {
325
- imgMaxWidth = reducedWidth;
326
- imgMaxHeight = reducedWidth / naturalRatio;
327
- } else {
328
- imgMaxWidth = imgMaxHeight * naturalRatio;
329
- }
330
- }
331
- containerWidth = imgMaxWidth;
332
- containerHeight = imgMaxHeight;
333
- imgRatio = imgMaxWidth / imgMaxHeight;
334
- if (originalRatio > imgRatio) {
335
- containerMaxWidth = imgMaxWidth;
336
- containerMaxHeight = containerMaxWidth / originalRatio;
337
- } else {
338
- containerMaxHeight = imgMaxHeight;
339
- containerMaxWidth = containerMaxHeight * originalRatio;
340
- }
341
- }
342
311
  if (originalWidth > containerWidth || originalHeight > containerHeight) {
343
312
  containerWidth = originalWidth;
344
313
  containerHeight = originalHeight;
@@ -362,23 +331,37 @@ var { state, actions, callbacks } = store(
362
331
  containerHeight
363
332
  );
364
333
  const targetContainerRatio = targetMaxWidth / targetMaxHeight;
365
- if (originalRatio > targetContainerRatio) {
334
+ if (fullSizeRatio > targetContainerRatio) {
366
335
  containerWidth = targetMaxWidth;
367
- containerHeight = containerWidth / originalRatio;
336
+ containerHeight = containerWidth / fullSizeRatio;
368
337
  } else {
369
338
  containerHeight = targetMaxHeight;
370
- containerWidth = containerHeight * originalRatio;
339
+ containerWidth = containerHeight * fullSizeRatio;
371
340
  }
372
- const containerScale = originalWidth / containerWidth;
373
- const lightboxImgWidth = imgMaxWidth * (containerWidth / containerMaxWidth);
374
- const lightboxImgHeight = imgMaxHeight * (containerHeight / containerMaxHeight);
341
+ const hasCroppedSource = naturalRatio.toFixed(2) !== fullSizeRatio.toFixed(2);
342
+ const sourceRatio = hasCroppedSource ? naturalRatio : fullSizeRatio;
343
+ const containerScale = Math.max(
344
+ originalWidth / containerWidth,
345
+ originalHeight / containerHeight,
346
+ originalWidth / (containerHeight * sourceRatio),
347
+ originalHeight * sourceRatio / containerWidth
348
+ );
349
+ const thumbnailWidth = originalWidth / containerScale;
350
+ const thumbnailHeight = originalHeight / containerScale;
351
+ const cropX = (containerWidth - thumbnailWidth) / 2;
352
+ const cropY = (containerHeight - thumbnailHeight) / 2;
353
+ screenPosX -= cropX * containerScale;
354
+ screenPosY -= cropY * containerScale;
375
355
  state.overlayStyles = `
376
356
  --wp--lightbox-initial-top-position: ${screenPosY}px;
377
357
  --wp--lightbox-initial-left-position: ${screenPosX}px;
378
358
  --wp--lightbox-container-width: ${containerWidth + 1}px;
379
359
  --wp--lightbox-container-height: ${containerHeight + 1}px;
380
- --wp--lightbox-image-width: ${lightboxImgWidth}px;
381
- --wp--lightbox-image-height: ${lightboxImgHeight}px;
360
+ --wp--lightbox-image-width: ${containerWidth}px;
361
+ --wp--lightbox-image-height: ${containerHeight}px;
362
+ --wp--lightbox-initial-clip: inset(${cropY}px ${cropX}px);
363
+ --wp--lightbox-thumbnail-width: ${hasCroppedSource ? thumbnailWidth : containerWidth}px;
364
+ --wp--lightbox-thumbnail-height: ${hasCroppedSource ? thumbnailHeight : containerHeight}px;
382
365
  --wp--lightbox-scale: ${containerScale};
383
366
  --wp--lightbox-scrollbar-width: ${window.innerWidth - document.documentElement.clientWidth}px;
384
367
  `;
@@ -439,13 +422,24 @@ var { state, actions, callbacks } = store(
439
422
  }
440
423
  },
441
424
  setInertElements() {
442
- document.querySelectorAll("body > :not(.wp-lightbox-overlay)").forEach((el) => {
443
- if (state.overlayEnabled) {
444
- el.setAttribute("inert", "");
445
- } else {
446
- el.removeAttribute("inert");
425
+ if (!state.overlayEnabled) {
426
+ inertElements.forEach(
427
+ (el) => el.removeAttribute("inert")
428
+ );
429
+ inertElements = [];
430
+ return;
431
+ }
432
+ const { ref } = getElement();
433
+ let node = ref;
434
+ while (node && node !== document.body && node.parentElement) {
435
+ for (const sibling of node.parentElement.children) {
436
+ if (sibling !== node && !sibling.hasAttribute("inert")) {
437
+ sibling.setAttribute("inert", "");
438
+ inertElements.push(sibling);
439
+ }
447
440
  }
448
- });
441
+ node = node.parentElement;
442
+ }
449
443
  },
450
444
  initTriggerButton() {
451
445
  const { imageId } = getContext();