@wordpress/block-library 8.29.0 → 8.30.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 (347) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/audio/edit.js +7 -17
  3. package/build/audio/edit.js.map +1 -1
  4. package/build/audio/edit.native.js.map +1 -1
  5. package/build/avatar/edit.js.map +1 -1
  6. package/build/block/deprecated.js +71 -11
  7. package/build/block/deprecated.js.map +1 -1
  8. package/build/block/edit.js +49 -24
  9. package/build/block/edit.js.map +1 -1
  10. package/build/button/edit.js +2 -2
  11. package/build/button/edit.js.map +1 -1
  12. package/build/buttons/edit.native.js.map +1 -1
  13. package/build/buttons/transforms.js +16 -2
  14. package/build/buttons/transforms.js.map +1 -1
  15. package/build/code/transforms.js +17 -6
  16. package/build/code/transforms.js.map +1 -1
  17. package/build/columns/edit.js +3 -2
  18. package/build/columns/edit.js.map +1 -1
  19. package/build/comment-author-avatar/edit.js +1 -1
  20. package/build/comment-author-avatar/edit.js.map +1 -1
  21. package/build/cover/edit/block-controls.js +14 -3
  22. package/build/cover/edit/block-controls.js.map +1 -1
  23. package/build/cover/edit/index.js.map +1 -1
  24. package/build/cover/edit/inspector-controls.js.map +1 -1
  25. package/build/cover/edit/resizable-cover-popover.js +0 -6
  26. package/build/cover/edit/resizable-cover-popover.js.map +1 -1
  27. package/build/cover/edit.native.js.map +1 -1
  28. package/build/file/deprecated.js.map +1 -1
  29. package/build/file/edit.js +6 -13
  30. package/build/file/edit.js.map +1 -1
  31. package/build/file/edit.native.js.map +1 -1
  32. package/build/file/save.js.map +1 -1
  33. package/build/form-input/edit.js +1 -1
  34. package/build/form-input/edit.js.map +1 -1
  35. package/build/gallery/edit.js.map +1 -1
  36. package/build/gallery/gallery.native.js.map +1 -1
  37. package/build/gallery/v1/edit.js.map +1 -1
  38. package/build/gallery/v1/gallery.native.js.map +1 -1
  39. package/build/heading/transforms.js +17 -4
  40. package/build/heading/transforms.js.map +1 -1
  41. package/build/image/edit.js +8 -4
  42. package/build/image/edit.js.map +1 -1
  43. package/build/image/edit.native.js.map +1 -1
  44. package/build/image/image.js +22 -8
  45. package/build/image/image.js.map +1 -1
  46. package/build/latest-posts/edit.native.js.map +1 -1
  47. package/build/list/ordered-list-settings.js +1 -1
  48. package/build/list/ordered-list-settings.js.map +1 -1
  49. package/build/list-item/edit.js +1 -3
  50. package/build/list-item/edit.js.map +1 -1
  51. package/build/list-item/edit.native.js.map +1 -1
  52. package/build/list-item/hooks/index.js +0 -7
  53. package/build/list-item/hooks/index.js.map +1 -1
  54. package/build/list-item/hooks/use-indent-list-item.js +1 -0
  55. package/build/list-item/hooks/use-indent-list-item.js.map +1 -1
  56. package/build/list-item/hooks/use-outdent-list-item.js +1 -0
  57. package/build/list-item/hooks/use-outdent-list-item.js.map +1 -1
  58. package/build/list-item/hooks/use-space.js +16 -7
  59. package/build/list-item/hooks/use-space.js.map +1 -1
  60. package/build/list-item/index.js +4 -1
  61. package/build/list-item/index.js.map +1 -1
  62. package/build/media-text/media-container.native.js +1 -1
  63. package/build/media-text/media-container.native.js.map +1 -1
  64. package/build/navigation/edit/index.js.map +1 -1
  65. package/build/navigation-link/link-ui.js.map +1 -1
  66. package/build/paragraph/edit.native.js.map +1 -1
  67. package/build/pattern/edit.js +11 -0
  68. package/build/pattern/edit.js.map +1 -1
  69. package/build/post-excerpt/edit.js.map +1 -1
  70. package/build/post-featured-image/dimension-controls.js.map +1 -1
  71. package/build/post-featured-image/edit.js +8 -11
  72. package/build/post-featured-image/edit.js.map +1 -1
  73. package/build/post-navigation-link/edit.js.map +1 -1
  74. package/build/post-title/edit.js +2 -2
  75. package/build/post-title/edit.js.map +1 -1
  76. package/build/query/edit/pattern-selection-modal.js.map +1 -1
  77. package/build/query/utils.js +7 -5
  78. package/build/query/utils.js.map +1 -1
  79. package/build/query-pagination-next/edit.js.map +1 -1
  80. package/build/query-pagination-previous/edit.js.map +1 -1
  81. package/build/quote/deprecated.js +111 -12
  82. package/build/quote/deprecated.js.map +1 -1
  83. package/build/quote/edit.js +5 -5
  84. package/build/quote/edit.js.map +1 -1
  85. package/build/quote/index.js +1 -1
  86. package/build/quote/index.js.map +1 -1
  87. package/build/quote/save.js +2 -2
  88. package/build/quote/save.js.map +1 -1
  89. package/build/read-more/edit.js.map +1 -1
  90. package/build/search/edit.js +1 -1
  91. package/build/search/edit.js.map +1 -1
  92. package/build/search/edit.native.js.map +1 -1
  93. package/build/site-logo/edit.js +7 -2
  94. package/build/site-logo/edit.js.map +1 -1
  95. package/build/site-title/{edit/index.js → edit.js} +1 -1
  96. package/build/site-title/edit.js.map +1 -0
  97. package/build/social-link/edit.js.map +1 -1
  98. package/build/social-links/edit.native.js.map +1 -1
  99. package/build/spacer/edit.js.map +1 -1
  100. package/build/table-of-contents/edit.js.map +1 -1
  101. package/build/template-part/edit/index.js +53 -1
  102. package/build/template-part/edit/index.js.map +1 -1
  103. package/build/template-part/edit/selection-modal.js +2 -8
  104. package/build/template-part/edit/selection-modal.js.map +1 -1
  105. package/build/template-part/edit/utils/map-template-part-to-block-pattern.js +30 -0
  106. package/build/template-part/edit/utils/map-template-part-to-block-pattern.js.map +1 -0
  107. package/build/utils/caption.js +15 -5
  108. package/build/utils/caption.js.map +1 -1
  109. package/build/utils/get-transformed-metadata.js +57 -0
  110. package/build/utils/get-transformed-metadata.js.map +1 -0
  111. package/build/utils/hooks.js +55 -4
  112. package/build/utils/hooks.js.map +1 -1
  113. package/build/video/edit-common-settings.js.map +1 -1
  114. package/build/video/edit.js +7 -16
  115. package/build/video/edit.js.map +1 -1
  116. package/build/video/edit.native.js +2 -7
  117. package/build/video/edit.native.js.map +1 -1
  118. package/build-module/audio/edit.js +10 -20
  119. package/build-module/audio/edit.js.map +1 -1
  120. package/build-module/audio/edit.native.js.map +1 -1
  121. package/build-module/avatar/edit.js.map +1 -1
  122. package/build-module/block/deprecated.js +71 -11
  123. package/build-module/block/deprecated.js.map +1 -1
  124. package/build-module/block/edit.js +49 -24
  125. package/build-module/block/edit.js.map +1 -1
  126. package/build-module/button/edit.js +3 -3
  127. package/build-module/button/edit.js.map +1 -1
  128. package/build-module/buttons/edit.native.js.map +1 -1
  129. package/build-module/buttons/transforms.js +16 -2
  130. package/build-module/buttons/transforms.js.map +1 -1
  131. package/build-module/code/transforms.js +17 -6
  132. package/build-module/code/transforms.js.map +1 -1
  133. package/build-module/columns/edit.js +3 -2
  134. package/build-module/columns/edit.js.map +1 -1
  135. package/build-module/comment-author-avatar/edit.js +1 -1
  136. package/build-module/comment-author-avatar/edit.js.map +1 -1
  137. package/build-module/cover/edit/block-controls.js +15 -4
  138. package/build-module/cover/edit/block-controls.js.map +1 -1
  139. package/build-module/cover/edit/index.js.map +1 -1
  140. package/build-module/cover/edit/inspector-controls.js.map +1 -1
  141. package/build-module/cover/edit/resizable-cover-popover.js +1 -7
  142. package/build-module/cover/edit/resizable-cover-popover.js.map +1 -1
  143. package/build-module/cover/edit.native.js.map +1 -1
  144. package/build-module/file/deprecated.js.map +1 -1
  145. package/build-module/file/edit.js +7 -14
  146. package/build-module/file/edit.js.map +1 -1
  147. package/build-module/file/edit.native.js.map +1 -1
  148. package/build-module/file/save.js.map +1 -1
  149. package/build-module/form-input/edit.js +1 -1
  150. package/build-module/form-input/edit.js.map +1 -1
  151. package/build-module/gallery/edit.js.map +1 -1
  152. package/build-module/gallery/gallery.native.js.map +1 -1
  153. package/build-module/gallery/v1/edit.js.map +1 -1
  154. package/build-module/gallery/v1/gallery.native.js.map +1 -1
  155. package/build-module/heading/transforms.js +17 -4
  156. package/build-module/heading/transforms.js.map +1 -1
  157. package/build-module/image/edit.js +9 -5
  158. package/build-module/image/edit.js.map +1 -1
  159. package/build-module/image/edit.native.js.map +1 -1
  160. package/build-module/image/image.js +23 -9
  161. package/build-module/image/image.js.map +1 -1
  162. package/build-module/latest-posts/edit.native.js.map +1 -1
  163. package/build-module/list/ordered-list-settings.js +1 -1
  164. package/build-module/list/ordered-list-settings.js.map +1 -1
  165. package/build-module/list-item/edit.js +2 -4
  166. package/build-module/list-item/edit.js.map +1 -1
  167. package/build-module/list-item/edit.native.js.map +1 -1
  168. package/build-module/list-item/hooks/index.js +0 -1
  169. package/build-module/list-item/hooks/index.js.map +1 -1
  170. package/build-module/list-item/hooks/use-indent-list-item.js +1 -0
  171. package/build-module/list-item/hooks/use-indent-list-item.js.map +1 -1
  172. package/build-module/list-item/hooks/use-outdent-list-item.js +1 -0
  173. package/build-module/list-item/hooks/use-outdent-list-item.js.map +1 -1
  174. package/build-module/list-item/hooks/use-space.js +17 -8
  175. package/build-module/list-item/hooks/use-space.js.map +1 -1
  176. package/build-module/list-item/index.js +4 -1
  177. package/build-module/list-item/index.js.map +1 -1
  178. package/build-module/media-text/media-container.native.js +1 -1
  179. package/build-module/media-text/media-container.native.js.map +1 -1
  180. package/build-module/navigation/edit/index.js.map +1 -1
  181. package/build-module/navigation-link/link-ui.js.map +1 -1
  182. package/build-module/paragraph/edit.native.js.map +1 -1
  183. package/build-module/pattern/edit.js +11 -0
  184. package/build-module/pattern/edit.js.map +1 -1
  185. package/build-module/post-excerpt/edit.js.map +1 -1
  186. package/build-module/post-featured-image/dimension-controls.js.map +1 -1
  187. package/build-module/post-featured-image/edit.js +9 -12
  188. package/build-module/post-featured-image/edit.js.map +1 -1
  189. package/build-module/post-navigation-link/edit.js.map +1 -1
  190. package/build-module/post-title/edit.js +2 -2
  191. package/build-module/post-title/edit.js.map +1 -1
  192. package/build-module/query/edit/pattern-selection-modal.js.map +1 -1
  193. package/build-module/query/utils.js +7 -5
  194. package/build-module/query/utils.js.map +1 -1
  195. package/build-module/query-pagination-next/edit.js.map +1 -1
  196. package/build-module/query-pagination-previous/edit.js.map +1 -1
  197. package/build-module/quote/deprecated.js +112 -13
  198. package/build-module/quote/deprecated.js.map +1 -1
  199. package/build-module/quote/edit.js +5 -5
  200. package/build-module/quote/edit.js.map +1 -1
  201. package/build-module/quote/index.js +1 -1
  202. package/build-module/quote/index.js.map +1 -1
  203. package/build-module/quote/save.js +2 -2
  204. package/build-module/quote/save.js.map +1 -1
  205. package/build-module/read-more/edit.js.map +1 -1
  206. package/build-module/search/edit.js +1 -1
  207. package/build-module/search/edit.js.map +1 -1
  208. package/build-module/search/edit.native.js.map +1 -1
  209. package/build-module/site-logo/edit.js +7 -2
  210. package/build-module/site-logo/edit.js.map +1 -1
  211. package/build-module/site-title/{edit/index.js → edit.js} +1 -1
  212. package/build-module/site-title/edit.js.map +1 -0
  213. package/build-module/social-link/edit.js.map +1 -1
  214. package/build-module/social-links/edit.native.js.map +1 -1
  215. package/build-module/spacer/edit.js.map +1 -1
  216. package/build-module/table-of-contents/edit.js.map +1 -1
  217. package/build-module/template-part/edit/index.js +57 -5
  218. package/build-module/template-part/edit/index.js.map +1 -1
  219. package/build-module/template-part/edit/selection-modal.js +2 -8
  220. package/build-module/template-part/edit/selection-modal.js.map +1 -1
  221. package/build-module/template-part/edit/utils/map-template-part-to-block-pattern.js +24 -0
  222. package/build-module/template-part/edit/utils/map-template-part-to-block-pattern.js.map +1 -0
  223. package/build-module/utils/caption.js +13 -3
  224. package/build-module/utils/caption.js.map +1 -1
  225. package/build-module/utils/get-transformed-metadata.js +51 -0
  226. package/build-module/utils/get-transformed-metadata.js.map +1 -0
  227. package/build-module/utils/hooks.js +54 -3
  228. package/build-module/utils/hooks.js.map +1 -1
  229. package/build-module/video/edit-common-settings.js.map +1 -1
  230. package/build-module/video/edit.js +10 -19
  231. package/build-module/video/edit.js.map +1 -1
  232. package/build-module/video/edit.native.js +2 -7
  233. package/build-module/video/edit.native.js.map +1 -1
  234. package/build-style/common-rtl.css +1 -0
  235. package/build-style/common.css +1 -0
  236. package/build-style/cover/style-rtl.css +2 -1
  237. package/build-style/cover/style.css +2 -1
  238. package/build-style/editor-rtl.css +4 -1
  239. package/build-style/editor.css +4 -1
  240. package/build-style/group/editor-rtl.css +1 -1
  241. package/build-style/group/editor.css +1 -1
  242. package/build-style/image/editor-rtl.css +3 -0
  243. package/build-style/image/editor.css +3 -0
  244. package/build-style/search/style-rtl.css +2 -0
  245. package/build-style/search/style.css +2 -0
  246. package/build-style/style-rtl.css +4 -1
  247. package/build-style/style.css +4 -1
  248. package/package.json +34 -34
  249. package/src/audio/edit.js +9 -19
  250. package/src/audio/edit.native.js +3 -3
  251. package/src/avatar/edit.js +1 -1
  252. package/src/block/deprecated.js +76 -11
  253. package/src/block/edit.js +64 -19
  254. package/src/block/index.php +23 -12
  255. package/src/button/edit.js +4 -3
  256. package/src/buttons/edit.native.js +1 -1
  257. package/src/buttons/transforms.js +14 -4
  258. package/src/calendar/index.php +5 -0
  259. package/src/code/transforms.js +20 -5
  260. package/src/columns/edit.js +3 -2
  261. package/src/comment-author-avatar/edit.js +1 -1
  262. package/src/comments/index.php +2 -0
  263. package/src/cover/edit/block-controls.js +16 -2
  264. package/src/cover/edit/index.js +2 -2
  265. package/src/cover/edit/inspector-controls.js +1 -1
  266. package/src/cover/edit/resizable-cover-popover.js +1 -6
  267. package/src/cover/edit.native.js +1 -1
  268. package/src/cover/style.scss +3 -2
  269. package/src/file/deprecated.js +3 -3
  270. package/src/file/edit.js +8 -15
  271. package/src/file/edit.native.js +4 -4
  272. package/src/file/save.js +1 -1
  273. package/src/footnotes/index.php +1 -1
  274. package/src/form-input/edit.js +1 -1
  275. package/src/gallery/edit.js +3 -3
  276. package/src/gallery/gallery.native.js +1 -1
  277. package/src/gallery/test/index.native.js +1 -1
  278. package/src/gallery/v1/edit.js +2 -2
  279. package/src/gallery/v1/gallery.native.js +1 -1
  280. package/src/group/editor.scss +1 -1
  281. package/src/heading/transforms.js +27 -8
  282. package/src/image/edit.js +13 -5
  283. package/src/image/edit.native.js +1 -1
  284. package/src/image/editor.scss +6 -0
  285. package/src/image/image.js +34 -22
  286. package/src/latest-posts/edit.native.js +1 -1
  287. package/src/list/ordered-list-settings.js +1 -1
  288. package/src/list-item/edit.js +1 -2
  289. package/src/list-item/edit.native.js +1 -1
  290. package/src/list-item/hooks/index.js +0 -1
  291. package/src/list-item/hooks/use-indent-list-item.js +2 -0
  292. package/src/list-item/hooks/use-outdent-list-item.js +2 -0
  293. package/src/list-item/hooks/use-space.js +16 -9
  294. package/src/list-item/index.js +3 -0
  295. package/src/media-text/media-container.native.js +5 -3
  296. package/src/media-text/test/edit.native.js +58 -0
  297. package/src/missing/test/edit-integration.native.js +2 -1
  298. package/src/navigation/edit/index.js +1 -1
  299. package/src/navigation/edit/test/navigation-menu-selector.js +3 -3
  300. package/src/navigation/index.php +26 -17
  301. package/src/navigation-link/link-ui.js +2 -2
  302. package/src/paragraph/edit.native.js +1 -1
  303. package/src/paragraph/test/edit.native.js +36 -0
  304. package/src/pattern/edit.js +14 -0
  305. package/src/post-excerpt/edit.js +1 -1
  306. package/src/post-featured-image/dimension-controls.js +4 -4
  307. package/src/post-featured-image/edit.js +10 -12
  308. package/src/post-navigation-link/edit.js +1 -1
  309. package/src/post-template/index.php +2 -0
  310. package/src/post-title/edit.js +49 -43
  311. package/src/query/edit/pattern-selection-modal.js +1 -1
  312. package/src/query/utils.js +6 -4
  313. package/src/query-pagination-next/edit.js +1 -1
  314. package/src/query-pagination-previous/edit.js +1 -1
  315. package/src/quote/block.json +1 -1
  316. package/src/quote/deprecated.js +110 -15
  317. package/src/quote/edit.js +5 -5
  318. package/src/quote/save.js +2 -2
  319. package/src/quote/test/__snapshots__/transforms.native.js.snap +2 -2
  320. package/src/read-more/edit.js +1 -1
  321. package/src/search/edit.js +1 -1
  322. package/src/search/edit.native.js +4 -4
  323. package/src/search/index.php +1 -1
  324. package/src/search/style.scss +2 -0
  325. package/src/site-logo/edit.js +11 -6
  326. package/src/social-link/edit.js +1 -1
  327. package/src/social-links/edit.native.js +1 -1
  328. package/src/spacer/edit.js +1 -1
  329. package/src/table-of-contents/edit.js +1 -1
  330. package/src/template-part/edit/index.js +91 -4
  331. package/src/template-part/edit/selection-modal.js +4 -8
  332. package/src/template-part/edit/utils/map-template-part-to-block-pattern.js +23 -0
  333. package/src/utils/caption.js +10 -1
  334. package/src/utils/get-transformed-metadata.js +65 -0
  335. package/src/utils/hooks.js +53 -3
  336. package/src/video/edit-common-settings.js +1 -1
  337. package/src/video/edit.js +10 -18
  338. package/src/video/edit.native.js +5 -8
  339. package/src/video/test/edit.native.js +0 -14
  340. package/build/list-item/hooks/use-copy.js +0 -39
  341. package/build/list-item/hooks/use-copy.js.map +0 -1
  342. package/build/site-title/edit/index.js.map +0 -1
  343. package/build-module/list-item/hooks/use-copy.js +0 -32
  344. package/build-module/list-item/hooks/use-copy.js.map +0 -1
  345. package/build-module/site-title/edit/index.js.map +0 -1
  346. package/src/list-item/hooks/use-copy.js +0 -38
  347. /package/src/site-title/{edit/index.js → edit.js} +0 -0
package/src/block/edit.js CHANGED
@@ -42,6 +42,25 @@ const { PARTIAL_SYNCING_SUPPORTED_BLOCKS } = unlock( patternsPrivateApis );
42
42
 
43
43
  const fullAlignments = [ 'full', 'wide', 'left', 'right' ];
44
44
 
45
+ function getLegacyIdMap( blocks, content, nameCount = {} ) {
46
+ let idToClientIdMap = {};
47
+ for ( const block of blocks ) {
48
+ if ( block?.innerBlocks?.length ) {
49
+ idToClientIdMap = {
50
+ ...idToClientIdMap,
51
+ ...getLegacyIdMap( block.innerBlocks, content, nameCount ),
52
+ };
53
+ }
54
+
55
+ const id = block.attributes.metadata?.id;
56
+ const clientId = block.clientId;
57
+ if ( id && content?.[ id ] ) {
58
+ idToClientIdMap[ clientId ] = id;
59
+ }
60
+ }
61
+ return idToClientIdMap;
62
+ }
63
+
45
64
  const useInferredLayout = ( blocks, parentLayout ) => {
46
65
  const initialInferredAlignmentRef = useRef();
47
66
 
@@ -101,25 +120,31 @@ function getOverridableAttributes( block ) {
101
120
  function applyInitialContentValuesToInnerBlocks(
102
121
  blocks,
103
122
  content = {},
104
- defaultValues
123
+ defaultValues,
124
+ legacyIdMap
105
125
  ) {
106
126
  return blocks.map( ( block ) => {
107
127
  const innerBlocks = applyInitialContentValuesToInnerBlocks(
108
128
  block.innerBlocks,
109
129
  content,
110
- defaultValues
130
+ defaultValues,
131
+ legacyIdMap
111
132
  );
112
- const blockId = block.attributes.metadata?.id;
113
- if ( ! hasOverridableAttributes( block ) || ! blockId )
133
+ const metadataName =
134
+ legacyIdMap?.[ block.clientId ] ?? block.attributes.metadata?.name;
135
+
136
+ if ( ! metadataName || ! hasOverridableAttributes( block ) ) {
114
137
  return { ...block, innerBlocks };
138
+ }
139
+
115
140
  const attributes = getOverridableAttributes( block );
116
141
  const newAttributes = { ...block.attributes };
117
142
  for ( const attributeKey of attributes ) {
118
- defaultValues[ blockId ] ??= {};
119
- defaultValues[ blockId ][ attributeKey ] =
143
+ defaultValues[ metadataName ] ??= {};
144
+ defaultValues[ metadataName ][ attributeKey ] =
120
145
  block.attributes[ attributeKey ];
121
146
 
122
- const contentValues = content[ blockId ]?.values;
147
+ const contentValues = content[ metadataName ];
123
148
  if ( contentValues?.[ attributeKey ] !== undefined ) {
124
149
  newAttributes[ attributeKey ] = contentValues[ attributeKey ];
125
150
  }
@@ -142,29 +167,40 @@ function isAttributeEqual( attribute1, attribute2 ) {
142
167
  return attribute1 === attribute2;
143
168
  }
144
169
 
145
- function getContentValuesFromInnerBlocks( blocks, defaultValues ) {
170
+ function getContentValuesFromInnerBlocks( blocks, defaultValues, legacyIdMap ) {
146
171
  /** @type {Record<string, { values: Record<string, unknown>}>} */
147
172
  const content = {};
148
173
  for ( const block of blocks ) {
149
174
  if ( block.name === patternBlockName ) continue;
150
- Object.assign(
151
- content,
152
- getContentValuesFromInnerBlocks( block.innerBlocks, defaultValues )
153
- );
154
- const blockId = block.attributes.metadata?.id;
155
- if ( ! hasOverridableAttributes( block ) || ! blockId ) continue;
175
+ if ( block.innerBlocks.length ) {
176
+ Object.assign(
177
+ content,
178
+ getContentValuesFromInnerBlocks(
179
+ block.innerBlocks,
180
+ defaultValues,
181
+ legacyIdMap
182
+ )
183
+ );
184
+ }
185
+ const metadataName =
186
+ legacyIdMap?.[ block.clientId ] ?? block.attributes.metadata?.name;
187
+ if ( ! metadataName || ! hasOverridableAttributes( block ) ) {
188
+ continue;
189
+ }
190
+
156
191
  const attributes = getOverridableAttributes( block );
192
+
157
193
  for ( const attributeKey of attributes ) {
158
194
  if (
159
195
  ! isAttributeEqual(
160
196
  block.attributes[ attributeKey ],
161
- defaultValues[ blockId ][ attributeKey ]
197
+ defaultValues?.[ metadataName ]?.[ attributeKey ]
162
198
  )
163
199
  ) {
164
- content[ blockId ] ??= { values: {}, blockName: block.name };
200
+ content[ metadataName ] ??= {};
165
201
  // TODO: We need a way to represent `undefined` in the serialized overrides.
166
202
  // Also see: https://github.com/WordPress/gutenberg/pull/57249#discussion_r1452987871
167
- content[ blockId ].values[ attributeKey ] =
203
+ content[ metadataName ][ attributeKey ] =
168
204
  block.attributes[ attributeKey ] === undefined
169
205
  ? // TODO: We use an empty string to represent undefined for now until
170
206
  // we support a richer format for overrides and the block binding API.
@@ -278,8 +314,15 @@ export default function ReusableBlockEdit( {
278
314
  [ editedRecord.blocks, editedRecord.content ]
279
315
  );
280
316
 
317
+ const legacyIdMap = useRef( {} );
318
+
281
319
  // Apply the initial overrides from the pattern block to the inner blocks.
282
320
  useEffect( () => {
321
+ // Build a map of clientIds to the old nano id system to provide back compat.
322
+ legacyIdMap.current = getLegacyIdMap(
323
+ initialBlocks,
324
+ initialContent.current
325
+ );
283
326
  defaultContent.current = {};
284
327
  const originalEditingMode = getBlockEditingMode( patternClientId );
285
328
  // Replace the contents of the blocks with the overrides.
@@ -291,7 +334,8 @@ export default function ReusableBlockEdit( {
291
334
  applyInitialContentValuesToInnerBlocks(
292
335
  initialBlocks,
293
336
  initialContent.current,
294
- defaultContent.current
337
+ defaultContent.current,
338
+ legacyIdMap.current
295
339
  )
296
340
  );
297
341
  } );
@@ -343,7 +387,8 @@ export default function ReusableBlockEdit( {
343
387
  setAttributes( {
344
388
  content: getContentValuesFromInnerBlocks(
345
389
  blocks,
346
- defaultContent.current
390
+ defaultContent.current,
391
+ legacyIdMap.current
347
392
  ),
348
393
  } );
349
394
  } );
@@ -8,6 +8,8 @@
8
8
  /**
9
9
  * Renders the `core/block` block on server.
10
10
  *
11
+ * @global WP_Embed $wp_embed
12
+ *
11
13
  * @param array $attributes The block attributes.
12
14
  *
13
15
  * @return string Rendered HTML of the referenced block.
@@ -46,26 +48,35 @@ function render_block_core_block( $attributes ) {
46
48
  $content = $wp_embed->run_shortcode( $reusable_block->post_content );
47
49
  $content = $wp_embed->autoembed( $content );
48
50
 
49
- // Back compat, the content attribute was previously named overrides and
50
- // had a slightly different format. For blocks that have not been migrated,
51
- // also convert the format here so that the provided `pattern/overrides`
52
- // context is correct.
53
- if ( isset( $attributes['overrides'] ) && ! isset( $attributes['content'] ) ) {
54
- $migrated_content = array();
55
- foreach ( $attributes['overrides'] as $id => $values ) {
56
- $migrated_content[ $id ] = array(
57
- 'values' => $values,
58
- );
51
+ // Back compat.
52
+ // For blocks that have not been migrated in the editor, add some back compat
53
+ // so that front-end rendering continues to work.
54
+
55
+ // This matches the `v2` deprecation. Removes the inner `values` property
56
+ // from every item.
57
+ if ( isset( $attributes['content'] ) ) {
58
+ foreach ( $attributes['content'] as &$content_data ) {
59
+ if ( isset( $content_data['values'] ) ) {
60
+ $is_assoc_array = is_array( $content_data['values'] ) && ! wp_is_numeric_array( $content_data['values'] );
61
+
62
+ if ( $is_assoc_array ) {
63
+ $content_data = $content_data['values'];
64
+ }
65
+ }
59
66
  }
60
- $attributes['content'] = $migrated_content;
61
67
  }
62
- $has_pattern_overrides = isset( $attributes['content'] );
68
+
69
+ // This matches the `v1` deprecation. Rename `overrides` to `content`.
70
+ if ( isset( $attributes['overrides'] ) && ! isset( $attributes['content'] ) ) {
71
+ $attributes['content'] = $attributes['overrides'];
72
+ }
63
73
 
64
74
  /**
65
75
  * We set the `pattern/overrides` context through the `render_block_context`
66
76
  * filter so that it is available when a pattern's inner blocks are
67
77
  * rendering via do_blocks given it only receives the inner content.
68
78
  */
79
+ $has_pattern_overrides = isset( $attributes['content'] );
69
80
  if ( $has_pattern_overrides ) {
70
81
  $filter_block_context = static function ( $context ) use ( $attributes ) {
71
82
  $context['pattern/overrides'] = $attributes['content'];
@@ -45,6 +45,7 @@ import {
45
45
  createBlock,
46
46
  cloneBlock,
47
47
  getDefaultBlockName,
48
+ store as blocksStore,
48
49
  } from '@wordpress/blocks';
49
50
  import { useMergeRefs, useRefEffect } from '@wordpress/compose';
50
51
  import { useSelect, useDispatch } from '@wordpress/data';
@@ -123,7 +124,7 @@ function WidthPanel( { selectedWidth, setAttributes } ) {
123
124
  }
124
125
 
125
126
  return (
126
- <PanelBody title={ __( 'Width settings' ) }>
127
+ <PanelBody title={ __( 'Settings' ) }>
127
128
  <ButtonGroup aria-label={ __( 'Button width' ) }>
128
129
  { [ 25, 50, 75, 100 ].map( ( widthValue ) => {
129
130
  return (
@@ -239,7 +240,7 @@ function ButtonEdit( props ) {
239
240
  }
240
241
 
241
242
  const blockBindingsSource = unlock(
242
- select( blockEditorStore )
243
+ select( blocksStore )
243
244
  ).getBlockBindingsSource( metadata?.bindings?.url?.source );
244
245
 
245
246
  return {
@@ -328,7 +329,7 @@ function ButtonEdit( props ) {
328
329
  title={ __( 'Unlink' ) }
329
330
  shortcut={ displayShortcut.primaryShift( 'k' ) }
330
331
  onClick={ unlink }
331
- isActive={ true }
332
+ isActive
332
333
  />
333
334
  ) }
334
335
  </BlockControls>
@@ -106,7 +106,7 @@ export default function ButtonsEdit( {
106
106
  const renderFooterAppender = useRef( () => (
107
107
  <View style={ styles.appenderContainer }>
108
108
  <InnerBlocks.ButtonBlockAppender
109
- isFloating={ true }
109
+ isFloating
110
110
  onAddBlock={ onAddNextButton }
111
111
  />
112
112
  </View>
@@ -4,6 +4,11 @@
4
4
  import { createBlock } from '@wordpress/blocks';
5
5
  import { __unstableCreateElement as createElement } from '@wordpress/rich-text';
6
6
 
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ import { getTransformedMetadata } from '../utils/get-transformed-metadata';
11
+
7
12
  const transforms = {
8
13
  from: [
9
14
  {
@@ -33,10 +38,8 @@ const transforms = {
33
38
  {},
34
39
  // Loop the selected buttons.
35
40
  buttons.map( ( attributes ) => {
36
- const element = createElement(
37
- document,
38
- attributes.content
39
- );
41
+ const { content, metadata } = attributes;
42
+ const element = createElement( document, content );
40
43
  // Remove any HTML tags.
41
44
  const text = element.innerText || '';
42
45
  // Get first url.
@@ -46,6 +49,13 @@ const transforms = {
46
49
  return createBlock( 'core/button', {
47
50
  text,
48
51
  url,
52
+ metadata: getTransformedMetadata(
53
+ metadata,
54
+ 'core/button',
55
+ ( { content: contentBinding } ) => ( {
56
+ text: contentBinding,
57
+ } )
58
+ ),
49
59
  } );
50
60
  } )
51
61
  ),
@@ -8,6 +8,9 @@
8
8
  /**
9
9
  * Renders the `core/calendar` block on server.
10
10
  *
11
+ * @global int $monthnum.
12
+ * @global int $year.
13
+ *
11
14
  * @param array $attributes The block attributes.
12
15
  *
13
16
  * @return string Returns the block content.
@@ -117,6 +120,8 @@ function block_core_calendar_has_published_posts() {
117
120
  * Queries the database for any published post and saves
118
121
  * a flag whether any published post exists or not.
119
122
  *
123
+ * @global wpdb $wpdb WordPress database abstraction object.
124
+ *
120
125
  * @return bool Has any published posts or not.
121
126
  */
122
127
  function block_core_calendar_update_has_published_posts() {
@@ -4,6 +4,11 @@
4
4
  import { createBlock } from '@wordpress/blocks';
5
5
  import { create, toHTMLString } from '@wordpress/rich-text';
6
6
 
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ import { getTransformedMetadata } from '../utils/get-transformed-metadata';
11
+
7
12
  const transforms = {
8
13
  from: [
9
14
  {
@@ -14,17 +19,21 @@ const transforms = {
14
19
  {
15
20
  type: 'block',
16
21
  blocks: [ 'core/paragraph' ],
17
- transform: ( { content } ) =>
18
- createBlock( 'core/code', { content } ),
22
+ transform: ( { content, metadata } ) =>
23
+ createBlock( 'core/code', {
24
+ content,
25
+ metadata: getTransformedMetadata( metadata, 'core/code' ),
26
+ } ),
19
27
  },
20
28
  {
21
29
  type: 'block',
22
30
  blocks: [ 'core/html' ],
23
- transform: ( { content: text } ) => {
31
+ transform: ( { content: text, metadata } ) => {
24
32
  return createBlock( 'core/code', {
25
33
  // The HTML is plain text (with plain line breaks), so
26
34
  // convert it to rich text.
27
35
  content: toHTMLString( { value: create( { text } ) } ),
36
+ metadata: getTransformedMetadata( metadata, 'core/code' ),
28
37
  } );
29
38
  },
30
39
  },
@@ -51,8 +60,14 @@ const transforms = {
51
60
  {
52
61
  type: 'block',
53
62
  blocks: [ 'core/paragraph' ],
54
- transform: ( { content } ) =>
55
- createBlock( 'core/paragraph', { content } ),
63
+ transform: ( { content, metadata } ) =>
64
+ createBlock( 'core/paragraph', {
65
+ content,
66
+ metadata: getTransformedMetadata(
67
+ metadata,
68
+ 'core/paragraph'
69
+ ),
70
+ } ),
56
71
  },
57
72
  ],
58
73
  };
@@ -139,18 +139,19 @@ function ColumnsEditContainer( { attributes, setAttributes, clientId } ) {
139
139
  // If adding a new column, assign width to the new column equal to
140
140
  // as if it were `1 / columns` of the total available space.
141
141
  const newColumnWidth = toWidthPrecision( 100 / newColumns );
142
+ const newlyAddedColumns = newColumns - previousColumns;
142
143
 
143
144
  // Redistribute in consideration of pending block insertion as
144
145
  // constraining the available working width.
145
146
  const widths = getRedistributedColumnWidths(
146
147
  innerBlocks,
147
- 100 - newColumnWidth
148
+ 100 - newColumnWidth * newlyAddedColumns
148
149
  );
149
150
 
150
151
  innerBlocks = [
151
152
  ...getMappedColumnWidths( innerBlocks, widths ),
152
153
  ...Array.from( {
153
- length: newColumns - previousColumns,
154
+ length: newlyAddedColumns,
154
155
  } ).map( () => {
155
156
  return createBlock( 'core/column', {
156
157
  width: `${ newColumnWidth }%`,
@@ -48,7 +48,7 @@ export default function Edit( {
48
48
 
49
49
  const inspectorControls = (
50
50
  <InspectorControls>
51
- <PanelBody title={ __( 'Avatar Settings' ) }>
51
+ <PanelBody title={ __( 'Settings' ) }>
52
52
  <RangeControl
53
53
  __nextHasNoMarginBottom
54
54
  __next40pxDefaultSize
@@ -16,6 +16,8 @@
16
16
  * the block is in legacy mode. If not, the HTML generated in the editor is
17
17
  * returned instead.
18
18
  *
19
+ * @global WP_Post $post Global post object.
20
+ *
19
21
  * @param array $attributes Block attributes.
20
22
  * @param string $content Block default content.
21
23
  * @param WP_Block $block Block instance.
@@ -8,6 +8,7 @@ import {
8
8
  MediaReplaceFlow,
9
9
  __experimentalBlockAlignmentMatrixControl as BlockAlignmentMatrixControl,
10
10
  __experimentalBlockFullHeightAligmentControl as FullHeightAlignmentControl,
11
+ privateApis as blockEditorPrivateApis,
11
12
  } from '@wordpress/block-editor';
12
13
  import { __ } from '@wordpress/i18n';
13
14
 
@@ -15,6 +16,9 @@ import { __ } from '@wordpress/i18n';
15
16
  * Internal dependencies
16
17
  */
17
18
  import { ALLOWED_MEDIA_TYPES } from '../shared';
19
+ import { unlock } from '../../lock-unlock';
20
+
21
+ const { cleanEmptyObject } = unlock( blockEditorPrivateApis );
18
22
 
19
23
  export default function CoverBlockControls( {
20
24
  attributes,
@@ -30,7 +34,10 @@ export default function CoverBlockControls( {
30
34
  const [ prevMinHeightValue, setPrevMinHeightValue ] = useState( minHeight );
31
35
  const [ prevMinHeightUnit, setPrevMinHeightUnit ] =
32
36
  useState( minHeightUnit );
33
- const isMinFullHeight = minHeightUnit === 'vh' && minHeight === 100;
37
+ const isMinFullHeight =
38
+ minHeightUnit === 'vh' &&
39
+ minHeight === 100 &&
40
+ ! attributes?.style?.dimensions?.aspectRatio;
34
41
  const toggleMinFullHeight = () => {
35
42
  if ( isMinFullHeight ) {
36
43
  // If there aren't previous values, take the default ones.
@@ -51,10 +58,17 @@ export default function CoverBlockControls( {
51
58
  setPrevMinHeightValue( minHeight );
52
59
  setPrevMinHeightUnit( minHeightUnit );
53
60
 
54
- // Set full height.
61
+ // Set full height, and clear any aspect ratio value.
55
62
  return setAttributes( {
56
63
  minHeight: 100,
57
64
  minHeightUnit: 'vh',
65
+ style: cleanEmptyObject( {
66
+ ...attributes?.style,
67
+ dimensions: {
68
+ ...attributes?.style?.dimensions,
69
+ aspectRatio: undefined, // Reset aspect ratio when minHeight is set.
70
+ },
71
+ } ),
58
72
  } );
59
73
  };
60
74
 
@@ -464,7 +464,7 @@ function CoverEdit( {
464
464
  >
465
465
  <div className="wp-block-cover__placeholder-background-options">
466
466
  <ColorPalette
467
- disableCustomColors={ true }
467
+ disableCustomColors
468
468
  value={ overlayColor.color }
469
469
  onChange={ onSetOverlayColor }
470
470
  clearable={ false }
@@ -525,7 +525,7 @@ function CoverEdit( {
525
525
  { ! url && useFeaturedImage && (
526
526
  <Placeholder
527
527
  className="wp-block-cover__image--placeholder-image"
528
- withIllustration={ true }
528
+ withIllustration
529
529
  />
530
530
  ) }
531
531
 
@@ -304,7 +304,7 @@ export default function CoverInspectorControls( {
304
304
  minHeight: undefined,
305
305
  minHeightUnit: undefined,
306
306
  } ) }
307
- isShownByDefault={ true }
307
+ isShownByDefault
308
308
  panelId={ clientId }
309
309
  >
310
310
  <CoverHeightInput
@@ -6,7 +6,7 @@ import classnames from 'classnames';
6
6
  /**
7
7
  * WordPress dependencies
8
8
  */
9
- import { useMemo, useState } from '@wordpress/element';
9
+ import { useState } from '@wordpress/element';
10
10
  import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
11
11
 
12
12
  /**
@@ -40,10 +40,6 @@ export default function ResizableCoverPopover( {
40
40
  ...props
41
41
  } ) {
42
42
  const [ isResizing, setIsResizing ] = useState( false );
43
- const dimensions = useMemo(
44
- () => ( { height, minHeight, width } ),
45
- [ minHeight, height, width ]
46
- );
47
43
 
48
44
  const resizableBoxProps = {
49
45
  className: classnames( className, { 'is-resizing': isResizing } ),
@@ -75,7 +71,6 @@ export default function ResizableCoverPopover( {
75
71
  return (
76
72
  <ResizableBoxPopover
77
73
  className="block-library-cover__resizable-box-popover"
78
- __unstableRefreshSize={ dimensions }
79
74
  resizableBoxProps={ resizableBoxProps }
80
75
  { ...props }
81
76
  />
@@ -538,7 +538,7 @@ const Cover = ( {
538
538
  <BottomSheetConsumer>
539
539
  { ( { shouldEnableBottomSheetScroll } ) => (
540
540
  <ColorPalette
541
- enableCustomColor={ true }
541
+ enableCustomColor
542
542
  customColorIndicatorStyles={
543
543
  styles.paletteColorIndicator
544
544
  }
@@ -8,9 +8,10 @@
8
8
  align-items: center;
9
9
  padding: 1em;
10
10
  // Prevent the `wp-block-cover__background` span from overflowing the container when border-radius is applied.
11
+ // `overflow: hidden` is provided as a fallback for browsers that don't support `overflow: clip`.
12
+ overflow: hidden;
11
13
  // Use clip instead of overflow: hidden so that sticky position works on child elements.
12
- // Use overflow-x instead of overflow so that aspect-ratio allows content to expand the area of the cover block.
13
- overflow-x: clip;
14
+ overflow: clip;
14
15
  // This block has customizable padding, border-box makes that more predictable.
15
16
  box-sizing: border-box;
16
17
  // Keep the flex layout direction to the physical direction (LTR) in RTL languages.
@@ -131,7 +131,7 @@ const v3 = {
131
131
  'wp-block-file__button',
132
132
  __experimentalGetElementClassName( 'button' )
133
133
  ) }
134
- download={ true }
134
+ download
135
135
  aria-describedby={ describedById }
136
136
  >
137
137
  <RichText.Content value={ downloadButtonText } />
@@ -259,7 +259,7 @@ const v2 = {
259
259
  <a
260
260
  href={ href }
261
261
  className="wp-block-file__button"
262
- download={ true }
262
+ download
263
263
  aria-describedby={ describedById }
264
264
  >
265
265
  <RichText.Content value={ downloadButtonText } />
@@ -372,7 +372,7 @@ const v1 = {
372
372
  <a
373
373
  href={ href }
374
374
  className="wp-block-file__button"
375
- download={ true }
375
+ download
376
376
  >
377
377
  <RichText.Content value={ downloadButtonText } />
378
378
  </a>
package/src/file/edit.js CHANGED
@@ -6,7 +6,7 @@ import classnames from 'classnames';
6
6
  /**
7
7
  * WordPress dependencies
8
8
  */
9
- import { getBlobByURL, isBlobURL, revokeBlobURL } from '@wordpress/blob';
9
+ import { isBlobURL } from '@wordpress/blob';
10
10
  import {
11
11
  __unstableGetAnimateClassName as getAnimateClassName,
12
12
  ResizableBox,
@@ -36,6 +36,7 @@ import { store as noticesStore } from '@wordpress/notices';
36
36
  import FileBlockInspector from './inspector';
37
37
  import { browserSupportsPdfs } from './utils';
38
38
  import removeAnchorTag from '../utils/remove-anchor-tag';
39
+ import { useUploadMediaFromBlobURL } from '../utils/hooks';
39
40
 
40
41
  export const MIN_PREVIEW_HEIGHT = 200;
41
42
  export const MAX_PREVIEW_HEIGHT = 2000;
@@ -72,7 +73,6 @@ function FileEdit( { attributes, isSelected, setAttributes, clientId } ) {
72
73
  displayPreview,
73
74
  previewHeight,
74
75
  } = attributes;
75
- const { getSettings } = useSelect( blockEditorStore );
76
76
  const { media } = useSelect(
77
77
  ( select ) => ( {
78
78
  media:
@@ -86,20 +86,13 @@ function FileEdit( { attributes, isSelected, setAttributes, clientId } ) {
86
86
  const { createErrorNotice } = useDispatch( noticesStore );
87
87
  const { toggleSelection } = useDispatch( blockEditorStore );
88
88
 
89
- useEffect( () => {
90
- // Upload a file drag-and-dropped into the editor.
91
- if ( isBlobURL( href ) ) {
92
- const file = getBlobByURL( href );
93
-
94
- getSettings().mediaUpload( {
95
- filesList: [ file ],
96
- onFileChange: ( [ newMedia ] ) => onSelectFile( newMedia ),
97
- onError: onUploadError,
98
- } );
99
-
100
- revokeBlobURL( href );
101
- }
89
+ useUploadMediaFromBlobURL( {
90
+ url: href,
91
+ onChange: onSelectFile,
92
+ onError: onUploadError,
93
+ } );
102
94
 
95
+ useEffect( () => {
103
96
  if ( RichText.isEmpty( downloadButtonText ) ) {
104
97
  setAttributes( {
105
98
  downloadButtonText: _x( 'Download', 'button label' ),
@@ -282,7 +282,7 @@ export class FileEdit extends Component {
282
282
  value={ textLinkHref }
283
283
  onChange={ this.onChangeLinkDestinationOption }
284
284
  options={ linkDestinationOptions }
285
- hideCancelButton={ true }
285
+ hideCancelButton
286
286
  />
287
287
  <ToggleControl
288
288
  icon={ external }
@@ -469,7 +469,7 @@ export class FileEdit extends Component {
469
469
  tagName="p"
470
470
  underlineColorAndroid="transparent"
471
471
  value={ fileName }
472
- deleteEnter={ true }
472
+ deleteEnter
473
473
  textAlign={ this.getTextAlignmentForAlignment(
474
474
  align
475
475
  ) }
@@ -505,7 +505,7 @@ export class FileEdit extends Component {
505
505
  textAlign="center"
506
506
  minWidth={ minWidth }
507
507
  maxWidth={ this.state.maxWidth }
508
- deleteEnter={ true }
508
+ deleteEnter
509
509
  style={ styles.buttonText }
510
510
  value={ downloadButtonText }
511
511
  placeholder={ placeholderText }
@@ -565,7 +565,7 @@ export class FileEdit extends Component {
565
565
  return (
566
566
  <MediaUpload
567
567
  allowedTypes={ [ MEDIA_TYPE_ANY ] }
568
- isReplacingMedia={ true }
568
+ isReplacingMedia
569
569
  onSelect={ this.onSelectFile }
570
570
  render={ ( { open, getMediaOptions } ) => {
571
571
  return this.getFileComponent( open, getMediaOptions );
package/src/file/save.js CHANGED
@@ -73,7 +73,7 @@ export default function save( { attributes } ) {
73
73
  'wp-block-file__button',
74
74
  __experimentalGetElementClassName( 'button' )
75
75
  ) }
76
- download={ true }
76
+ download
77
77
  aria-describedby={ describedById }
78
78
  >
79
79
  <RichText.Content value={ downloadButtonText } />
@@ -105,7 +105,7 @@ function register_block_core_footnotes_post_meta() {
105
105
  }
106
106
  }
107
107
  }
108
- /**
108
+ /*
109
109
  * Most post types are registered at priority 10, so use priority 20 here in
110
110
  * order to catch them.
111
111
  */