@wordpress/block-library 8.24.1 → 8.25.1-next.79a6196f.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 (509) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/LICENSE.md +1 -1
  3. package/build/audio/edit.js +15 -62
  4. package/build/audio/edit.js.map +1 -1
  5. package/build/audio/edit.native.js +1 -1
  6. package/build/audio/edit.native.js.map +1 -1
  7. package/build/audio/index.js +2 -2
  8. package/build/block/edit.js +157 -19
  9. package/build/block/edit.js.map +1 -1
  10. package/build/block/index.js +3 -2
  11. package/build/block/index.js.map +1 -1
  12. package/build/block/v1/edit.js +116 -0
  13. package/build/block/v1/edit.js.map +1 -0
  14. package/build/block/{edit.native.js → v1/edit.native.js} +2 -2
  15. package/build/block/v1/edit.native.js.map +1 -0
  16. package/build/button/index.js +2 -2
  17. package/build/button/save.js +1 -1
  18. package/build/button/save.js.map +1 -1
  19. package/build/code/edit.native.js +13 -14
  20. package/build/code/edit.native.js.map +1 -1
  21. package/build/code/index.js +2 -2
  22. package/build/code/save.js +6 -2
  23. package/build/code/save.js.map +1 -1
  24. package/build/comments-title/deprecated.js +1 -1
  25. package/build/comments-title/index.js +1 -1
  26. package/build/cover/edit/inspector-controls.js +1 -1
  27. package/build/cover/edit/inspector-controls.js.map +1 -1
  28. package/build/cover/edit.native.js +1 -0
  29. package/build/cover/edit.native.js.map +1 -1
  30. package/build/details/index.js +2 -2
  31. package/build/embed/deprecated.js +2 -2
  32. package/build/embed/embed-preview.native.js +1 -1
  33. package/build/embed/embed-preview.native.js.map +1 -1
  34. package/build/embed/icons.js +1 -1
  35. package/build/embed/icons.js.map +1 -1
  36. package/build/embed/index.js +2 -2
  37. package/build/embed/transforms.js +2 -2
  38. package/build/embed/util.js +6 -6
  39. package/build/embed/util.js.map +1 -1
  40. package/build/file/edit.js +20 -28
  41. package/build/file/edit.js.map +1 -1
  42. package/build/file/edit.native.js +1 -1
  43. package/build/file/edit.native.js.map +1 -1
  44. package/build/file/index.js +4 -4
  45. package/build/file/save.js +4 -1
  46. package/build/file/save.js.map +1 -1
  47. package/build/form-input/deprecated.js +147 -0
  48. package/build/form-input/deprecated.js.map +1 -0
  49. package/build/form-input/edit.js +1 -1
  50. package/build/form-input/edit.js.map +1 -1
  51. package/build/form-input/index.js +4 -2
  52. package/build/form-input/index.js.map +1 -1
  53. package/build/form-input/save.js +7 -9
  54. package/build/form-input/save.js.map +1 -1
  55. package/build/gallery/edit.js +38 -58
  56. package/build/gallery/edit.js.map +1 -1
  57. package/build/gallery/gallery.js +19 -24
  58. package/build/gallery/gallery.js.map +1 -1
  59. package/build/gallery/gallery.native.js +1 -1
  60. package/build/gallery/gallery.native.js.map +1 -1
  61. package/build/gallery/index.js +8 -4
  62. package/build/gallery/index.js.map +1 -1
  63. package/build/gallery/transforms.js +4 -68
  64. package/build/gallery/transforms.js.map +1 -1
  65. package/build/gallery/v1/gallery.native.js +1 -1
  66. package/build/gallery/v1/gallery.native.js.map +1 -1
  67. package/build/group/edit.js +6 -1
  68. package/build/group/edit.js.map +1 -1
  69. package/build/group/index.js +5 -1
  70. package/build/group/index.js.map +1 -1
  71. package/build/heading/index.js +3 -6
  72. package/build/heading/index.js.map +1 -1
  73. package/build/image/deprecated.js +11 -0
  74. package/build/image/deprecated.js.map +1 -1
  75. package/build/image/edit.native.js +4 -1
  76. package/build/image/edit.native.js.map +1 -1
  77. package/build/image/image.js +35 -71
  78. package/build/image/image.js.map +1 -1
  79. package/build/image/index.js +2 -2
  80. package/build/image/save.js +3 -1
  81. package/build/image/save.js.map +1 -1
  82. package/build/image/view.js +7 -1
  83. package/build/image/view.js.map +1 -1
  84. package/build/list/edit.js +10 -15
  85. package/build/list/edit.js.map +1 -1
  86. package/build/list-item/edit.js +17 -2
  87. package/build/list-item/edit.js.map +1 -1
  88. package/build/list-item/hooks/use-enter.js +5 -3
  89. package/build/list-item/hooks/use-enter.js.map +1 -1
  90. package/build/list-item/hooks/use-enter.native.js +4 -3
  91. package/build/list-item/hooks/use-enter.native.js.map +1 -1
  92. package/build/list-item/hooks/use-indent-list-item.js +2 -3
  93. package/build/list-item/hooks/use-indent-list-item.js.map +1 -1
  94. package/build/list-item/hooks/use-merge.js +1 -1
  95. package/build/list-item/hooks/use-merge.js.map +1 -1
  96. package/build/list-item/hooks/use-outdent-list-item.js +3 -17
  97. package/build/list-item/hooks/use-outdent-list-item.js.map +1 -1
  98. package/build/list-item/hooks/use-space.js +8 -4
  99. package/build/list-item/hooks/use-space.js.map +1 -1
  100. package/build/list-item/index.js +10 -3
  101. package/build/list-item/index.js.map +1 -1
  102. package/build/media-text/media-container.native.js +3 -0
  103. package/build/media-text/media-container.native.js.map +1 -1
  104. package/build/navigation/constants.js +3 -1
  105. package/build/navigation/constants.js.map +1 -1
  106. package/build/navigation/edit/index.js +5 -1
  107. package/build/navigation/edit/index.js.map +1 -1
  108. package/build/navigation/view.js +25 -1
  109. package/build/navigation/view.js.map +1 -1
  110. package/build/page-list/convert-to-links-modal.js +2 -2
  111. package/build/page-list/convert-to-links-modal.js.map +1 -1
  112. package/build/paragraph/edit.js +54 -32
  113. package/build/paragraph/edit.js.map +1 -1
  114. package/build/paragraph/index.js +2 -4
  115. package/build/paragraph/index.js.map +1 -1
  116. package/build/paragraph/transforms.js +2 -4
  117. package/build/paragraph/transforms.js.map +1 -1
  118. package/build/pattern/edit.js +24 -2
  119. package/build/pattern/edit.js.map +1 -1
  120. package/build/pattern/recursion-detector.js +147 -0
  121. package/build/pattern/recursion-detector.js.map +1 -0
  122. package/build/post-featured-image/edit.js +19 -2
  123. package/build/post-featured-image/edit.js.map +1 -1
  124. package/build/post-featured-image/index.js +4 -0
  125. package/build/post-featured-image/index.js.map +1 -1
  126. package/build/post-title/index.js +1 -3
  127. package/build/post-title/index.js.map +1 -1
  128. package/build/preformatted/index.js +2 -3
  129. package/build/preformatted/index.js.map +1 -1
  130. package/build/pullquote/index.js +5 -7
  131. package/build/pullquote/index.js.map +1 -1
  132. package/build/query/edit/inspector-controls/index.js +3 -1
  133. package/build/query/edit/inspector-controls/index.js.map +1 -1
  134. package/build/query/edit/inspector-controls/taxonomy-controls.js +2 -0
  135. package/build/query/edit/inspector-controls/taxonomy-controls.js.map +1 -1
  136. package/build/query-pagination-numbers/index.js +1 -1
  137. package/build/query-title/index.js +1 -3
  138. package/build/query-title/index.js.map +1 -1
  139. package/build/quote/index.js +3 -5
  140. package/build/quote/index.js.map +1 -1
  141. package/build/quote/transforms.js +7 -6
  142. package/build/quote/transforms.js.map +1 -1
  143. package/build/search/edit.js +3 -5
  144. package/build/search/edit.js.map +1 -1
  145. package/build/search/index.js +0 -4
  146. package/build/search/index.js.map +1 -1
  147. package/build/site-logo/edit.js +7 -6
  148. package/build/site-logo/edit.js.map +1 -1
  149. package/build/site-title/index.js +1 -5
  150. package/build/site-title/index.js.map +1 -1
  151. package/build/social-link/icons/gravatar.js +22 -0
  152. package/build/social-link/icons/gravatar.js.map +1 -0
  153. package/build/social-link/icons/index.js +11 -0
  154. package/build/social-link/icons/index.js.map +1 -1
  155. package/build/social-link/variations.js +7 -0
  156. package/build/social-link/variations.js.map +1 -1
  157. package/build/spacer/edit.native.js +2 -2
  158. package/build/spacer/edit.native.js.map +1 -1
  159. package/build/table/edit.js +3 -1
  160. package/build/table/edit.js.map +1 -1
  161. package/build/table/index.js +9 -10
  162. package/build/table/index.js.map +1 -1
  163. package/build/table-of-contents/edit.js +2 -2
  164. package/build/table-of-contents/edit.js.map +1 -1
  165. package/build/table-of-contents/index.js +5 -2
  166. package/build/table-of-contents/index.js.map +1 -1
  167. package/build/tag-cloud/edit.js +5 -9
  168. package/build/tag-cloud/edit.js.map +1 -1
  169. package/build/utils/caption.js +90 -0
  170. package/build/utils/caption.js.map +1 -0
  171. package/build/utils/constants.js +16 -0
  172. package/build/utils/constants.js.map +1 -0
  173. package/build/utils/remove-anchor-tag.js +2 -1
  174. package/build/utils/remove-anchor-tag.js.map +1 -1
  175. package/build/verse/index.js +3 -5
  176. package/build/verse/index.js.map +1 -1
  177. package/build/video/deprecated.js +2 -2
  178. package/build/video/edit.js +16 -57
  179. package/build/video/edit.js.map +1 -1
  180. package/build/video/edit.native.js +1 -1
  181. package/build/video/edit.native.js.map +1 -1
  182. package/build/video/index.js +2 -2
  183. package/build-module/audio/edit.js +19 -66
  184. package/build-module/audio/edit.js.map +1 -1
  185. package/build-module/audio/edit.native.js +2 -2
  186. package/build-module/audio/edit.native.js.map +1 -1
  187. package/build-module/audio/index.js +2 -2
  188. package/build-module/block/edit.js +160 -22
  189. package/build-module/block/edit.js.map +1 -1
  190. package/build-module/block/index.js +3 -2
  191. package/build-module/block/index.js.map +1 -1
  192. package/build-module/block/v1/edit.js +108 -0
  193. package/build-module/block/v1/edit.js.map +1 -0
  194. package/build-module/block/{edit.native.js → v1/edit.native.js} +2 -2
  195. package/build-module/block/v1/edit.native.js.map +1 -0
  196. package/build-module/button/index.js +2 -2
  197. package/build-module/button/save.js +1 -1
  198. package/build-module/button/save.js.map +1 -1
  199. package/build-module/code/edit.native.js +14 -16
  200. package/build-module/code/edit.native.js.map +1 -1
  201. package/build-module/code/index.js +2 -2
  202. package/build-module/code/save.js +6 -2
  203. package/build-module/code/save.js.map +1 -1
  204. package/build-module/comments-title/deprecated.js +1 -1
  205. package/build-module/comments-title/index.js +1 -1
  206. package/build-module/cover/edit/inspector-controls.js +1 -1
  207. package/build-module/cover/edit/inspector-controls.js.map +1 -1
  208. package/build-module/cover/edit.native.js +1 -0
  209. package/build-module/cover/edit.native.js.map +1 -1
  210. package/build-module/details/index.js +2 -2
  211. package/build-module/embed/deprecated.js +2 -2
  212. package/build-module/embed/embed-preview.native.js +2 -2
  213. package/build-module/embed/embed-preview.native.js.map +1 -1
  214. package/build-module/embed/icons.js +1 -1
  215. package/build-module/embed/icons.js.map +1 -1
  216. package/build-module/embed/index.js +2 -2
  217. package/build-module/embed/transforms.js +2 -2
  218. package/build-module/embed/util.js +6 -6
  219. package/build-module/embed/util.js.map +1 -1
  220. package/build-module/file/edit.js +20 -28
  221. package/build-module/file/edit.js.map +1 -1
  222. package/build-module/file/edit.native.js +1 -1
  223. package/build-module/file/edit.native.js.map +1 -1
  224. package/build-module/file/index.js +4 -4
  225. package/build-module/file/save.js +4 -1
  226. package/build-module/file/save.js.map +1 -1
  227. package/build-module/form-input/deprecated.js +138 -0
  228. package/build-module/form-input/deprecated.js.map +1 -0
  229. package/build-module/form-input/edit.js +1 -1
  230. package/build-module/form-input/edit.js.map +1 -1
  231. package/build-module/form-input/index.js +4 -2
  232. package/build-module/form-input/index.js.map +1 -1
  233. package/build-module/form-input/save.js +8 -10
  234. package/build-module/form-input/save.js.map +1 -1
  235. package/build-module/gallery/edit.js +41 -61
  236. package/build-module/gallery/edit.js.map +1 -1
  237. package/build-module/gallery/gallery.js +18 -21
  238. package/build-module/gallery/gallery.js.map +1 -1
  239. package/build-module/gallery/gallery.native.js +2 -2
  240. package/build-module/gallery/gallery.native.js.map +1 -1
  241. package/build-module/gallery/index.js +8 -4
  242. package/build-module/gallery/index.js.map +1 -1
  243. package/build-module/gallery/transforms.js +4 -68
  244. package/build-module/gallery/transforms.js.map +1 -1
  245. package/build-module/gallery/v1/gallery.native.js +2 -2
  246. package/build-module/gallery/v1/gallery.native.js.map +1 -1
  247. package/build-module/group/edit.js +6 -1
  248. package/build-module/group/edit.js.map +1 -1
  249. package/build-module/group/index.js +5 -1
  250. package/build-module/group/index.js.map +1 -1
  251. package/build-module/heading/index.js +3 -6
  252. package/build-module/heading/index.js.map +1 -1
  253. package/build-module/image/deprecated.js +11 -0
  254. package/build-module/image/deprecated.js.map +1 -1
  255. package/build-module/image/edit.native.js +5 -2
  256. package/build-module/image/edit.native.js.map +1 -1
  257. package/build-module/image/image.js +35 -71
  258. package/build-module/image/image.js.map +1 -1
  259. package/build-module/image/index.js +2 -2
  260. package/build-module/image/save.js +3 -1
  261. package/build-module/image/save.js.map +1 -1
  262. package/build-module/image/view.js +7 -1
  263. package/build-module/image/view.js.map +1 -1
  264. package/build-module/list/edit.js +10 -15
  265. package/build-module/list/edit.js.map +1 -1
  266. package/build-module/list-item/edit.js +18 -3
  267. package/build-module/list-item/edit.js.map +1 -1
  268. package/build-module/list-item/hooks/use-enter.js +5 -3
  269. package/build-module/list-item/hooks/use-enter.js.map +1 -1
  270. package/build-module/list-item/hooks/use-enter.native.js +4 -3
  271. package/build-module/list-item/hooks/use-enter.native.js.map +1 -1
  272. package/build-module/list-item/hooks/use-indent-list-item.js +2 -3
  273. package/build-module/list-item/hooks/use-indent-list-item.js.map +1 -1
  274. package/build-module/list-item/hooks/use-merge.js +1 -1
  275. package/build-module/list-item/hooks/use-merge.js.map +1 -1
  276. package/build-module/list-item/hooks/use-outdent-list-item.js +3 -17
  277. package/build-module/list-item/hooks/use-outdent-list-item.js.map +1 -1
  278. package/build-module/list-item/hooks/use-space.js +8 -4
  279. package/build-module/list-item/hooks/use-space.js.map +1 -1
  280. package/build-module/list-item/index.js +10 -3
  281. package/build-module/list-item/index.js.map +1 -1
  282. package/build-module/media-text/media-container.native.js +3 -0
  283. package/build-module/media-text/media-container.native.js.map +1 -1
  284. package/build-module/navigation/constants.js +1 -0
  285. package/build-module/navigation/constants.js.map +1 -1
  286. package/build-module/navigation/edit/index.js +7 -3
  287. package/build-module/navigation/edit/index.js.map +1 -1
  288. package/build-module/navigation/view.js +25 -1
  289. package/build-module/navigation/view.js.map +1 -1
  290. package/build-module/page-list/convert-to-links-modal.js +2 -2
  291. package/build-module/page-list/convert-to-links-modal.js.map +1 -1
  292. package/build-module/paragraph/edit.js +54 -32
  293. package/build-module/paragraph/edit.js.map +1 -1
  294. package/build-module/paragraph/index.js +2 -4
  295. package/build-module/paragraph/index.js.map +1 -1
  296. package/build-module/paragraph/transforms.js +2 -4
  297. package/build-module/paragraph/transforms.js.map +1 -1
  298. package/build-module/pattern/edit.js +26 -4
  299. package/build-module/pattern/edit.js.map +1 -1
  300. package/build-module/pattern/recursion-detector.js +139 -0
  301. package/build-module/pattern/recursion-detector.js.map +1 -0
  302. package/build-module/post-featured-image/edit.js +19 -2
  303. package/build-module/post-featured-image/edit.js.map +1 -1
  304. package/build-module/post-featured-image/index.js +4 -0
  305. package/build-module/post-featured-image/index.js.map +1 -1
  306. package/build-module/post-title/index.js +1 -3
  307. package/build-module/post-title/index.js.map +1 -1
  308. package/build-module/preformatted/index.js +2 -3
  309. package/build-module/preformatted/index.js.map +1 -1
  310. package/build-module/pullquote/index.js +5 -7
  311. package/build-module/pullquote/index.js.map +1 -1
  312. package/build-module/query/edit/inspector-controls/index.js +3 -1
  313. package/build-module/query/edit/inspector-controls/index.js.map +1 -1
  314. package/build-module/query/edit/inspector-controls/taxonomy-controls.js +2 -0
  315. package/build-module/query/edit/inspector-controls/taxonomy-controls.js.map +1 -1
  316. package/build-module/query-pagination-numbers/index.js +1 -1
  317. package/build-module/query-title/index.js +1 -3
  318. package/build-module/query-title/index.js.map +1 -1
  319. package/build-module/quote/index.js +3 -5
  320. package/build-module/quote/index.js.map +1 -1
  321. package/build-module/quote/transforms.js +7 -6
  322. package/build-module/quote/transforms.js.map +1 -1
  323. package/build-module/search/edit.js +3 -5
  324. package/build-module/search/edit.js.map +1 -1
  325. package/build-module/search/index.js +0 -4
  326. package/build-module/search/index.js.map +1 -1
  327. package/build-module/site-logo/edit.js +7 -6
  328. package/build-module/site-logo/edit.js.map +1 -1
  329. package/build-module/site-title/index.js +1 -5
  330. package/build-module/site-title/index.js.map +1 -1
  331. package/build-module/social-link/icons/gravatar.js +14 -0
  332. package/build-module/social-link/icons/gravatar.js.map +1 -0
  333. package/build-module/social-link/icons/index.js +1 -0
  334. package/build-module/social-link/icons/index.js.map +1 -1
  335. package/build-module/social-link/variations.js +8 -1
  336. package/build-module/social-link/variations.js.map +1 -1
  337. package/build-module/spacer/edit.native.js +2 -2
  338. package/build-module/spacer/edit.native.js.map +1 -1
  339. package/build-module/table/edit.js +3 -1
  340. package/build-module/table/edit.js.map +1 -1
  341. package/build-module/table/index.js +9 -10
  342. package/build-module/table/index.js.map +1 -1
  343. package/build-module/table-of-contents/edit.js +1 -1
  344. package/build-module/table-of-contents/edit.js.map +1 -1
  345. package/build-module/table-of-contents/index.js +5 -1
  346. package/build-module/table-of-contents/index.js.map +1 -1
  347. package/build-module/tag-cloud/edit.js +6 -10
  348. package/build-module/tag-cloud/edit.js.map +1 -1
  349. package/build-module/utils/caption.js +82 -0
  350. package/build-module/utils/caption.js.map +1 -0
  351. package/build-module/utils/constants.js +9 -0
  352. package/build-module/utils/constants.js.map +1 -0
  353. package/build-module/utils/remove-anchor-tag.js +2 -1
  354. package/build-module/utils/remove-anchor-tag.js.map +1 -1
  355. package/build-module/verse/index.js +3 -5
  356. package/build-module/verse/index.js.map +1 -1
  357. package/build-module/video/deprecated.js +2 -2
  358. package/build-module/video/edit.js +21 -62
  359. package/build-module/video/edit.js.map +1 -1
  360. package/build-module/video/edit.native.js +2 -2
  361. package/build-module/video/edit.native.js.map +1 -1
  362. package/build-module/video/index.js +2 -2
  363. package/build-style/button/editor-rtl.css +0 -37
  364. package/build-style/button/editor.css +0 -37
  365. package/build-style/button/style-rtl.css +6 -6
  366. package/build-style/button/style.css +6 -6
  367. package/build-style/editor-rtl.css +3 -55
  368. package/build-style/editor.css +3 -55
  369. package/build-style/navigation/editor-rtl.css +2 -4
  370. package/build-style/navigation/editor.css +2 -4
  371. package/build-style/navigation/style-rtl.css +14 -18
  372. package/build-style/navigation/style.css +14 -18
  373. package/build-style/search/style-rtl.css +26 -27
  374. package/build-style/search/style.css +26 -27
  375. package/build-style/social-links/style-rtl.css +14 -2
  376. package/build-style/social-links/style.css +14 -2
  377. package/build-style/style-rtl.css +60 -53
  378. package/build-style/style.css +60 -53
  379. package/build-style/table/editor-rtl.css +1 -14
  380. package/build-style/table/editor.css +1 -14
  381. package/package.json +32 -32
  382. package/src/audio/block.json +2 -2
  383. package/src/audio/edit.js +29 -92
  384. package/src/audio/edit.native.js +2 -1
  385. package/src/audio/test/__snapshots__/edit.native.js.snap +12 -0
  386. package/src/audio/test/edit.native.js +29 -0
  387. package/src/block/edit.js +218 -37
  388. package/src/block/index.js +3 -2
  389. package/src/block/index.php +48 -0
  390. package/src/block/v1/edit.js +163 -0
  391. package/src/block/{edit.native.js → v1/edit.native.js} +2 -2
  392. package/src/button/block.json +2 -2
  393. package/src/button/editor.scss +0 -43
  394. package/src/button/save.js +1 -1
  395. package/src/button/style.scss +6 -6
  396. package/src/buttons/test/__snapshots__/edit.native.js.snap +6 -0
  397. package/src/buttons/test/edit.native.js +49 -0
  398. package/src/code/block.json +2 -2
  399. package/src/code/edit.native.js +11 -13
  400. package/src/code/save.js +4 -1
  401. package/src/code/test/edit.native.js +2 -2
  402. package/src/comments-title/block.json +1 -1
  403. package/src/cover/edit/inspector-controls.js +1 -1
  404. package/src/cover/edit.native.js +1 -0
  405. package/src/cover/test/edit.native.js +7 -1
  406. package/src/details/block.json +2 -2
  407. package/src/embed/block.json +2 -2
  408. package/src/embed/embed-preview.native.js +2 -1
  409. package/src/embed/icons.js +1 -1
  410. package/src/embed/util.js +2 -2
  411. package/src/file/block.json +4 -4
  412. package/src/file/edit.js +18 -25
  413. package/src/file/edit.native.js +1 -1
  414. package/src/file/save.js +5 -1
  415. package/src/form-input/block.json +2 -2
  416. package/src/form-input/deprecated.js +142 -0
  417. package/src/form-input/edit.js +1 -1
  418. package/src/form-input/index.js +2 -0
  419. package/src/form-input/save.js +27 -24
  420. package/src/gallery/block.json +8 -4
  421. package/src/gallery/edit.js +70 -98
  422. package/src/gallery/gallery.js +22 -36
  423. package/src/gallery/gallery.native.js +6 -2
  424. package/src/gallery/index.php +15 -0
  425. package/src/gallery/transforms.js +2 -55
  426. package/src/gallery/v1/gallery.native.js +2 -1
  427. package/src/group/block.json +5 -1
  428. package/src/group/edit.js +4 -1
  429. package/src/heading/block.json +3 -6
  430. package/src/image/block.json +2 -2
  431. package/src/image/deprecated.js +8 -0
  432. package/src/image/edit.native.js +5 -3
  433. package/src/image/image.js +77 -127
  434. package/src/image/index.php +1 -6
  435. package/src/image/save.js +3 -1
  436. package/src/image/view.js +5 -2
  437. package/src/list/edit.js +27 -35
  438. package/src/list-item/block.json +10 -3
  439. package/src/list-item/edit.js +18 -2
  440. package/src/list-item/hooks/use-enter.js +63 -62
  441. package/src/list-item/hooks/use-enter.native.js +9 -5
  442. package/src/list-item/hooks/use-indent-list-item.js +43 -53
  443. package/src/list-item/hooks/use-merge.js +1 -1
  444. package/src/list-item/hooks/use-outdent-list-item.js +50 -69
  445. package/src/list-item/hooks/use-space.js +7 -4
  446. package/src/media-text/media-container.native.js +3 -1
  447. package/src/navigation/constants.js +2 -0
  448. package/src/navigation/edit/index.js +18 -3
  449. package/src/navigation/editor.scss +1 -1
  450. package/src/navigation/index.php +1 -1
  451. package/src/navigation/style.scss +18 -16
  452. package/src/navigation/view.js +29 -3
  453. package/src/navigation-link/test/__snapshots__/hooks.js.snap +6 -3
  454. package/src/page-list/convert-to-links-modal.js +2 -2
  455. package/src/paragraph/block.json +2 -4
  456. package/src/paragraph/edit.js +53 -40
  457. package/src/paragraph/test/__snapshots__/edit.native.js.snap +12 -0
  458. package/src/paragraph/test/edit.native.js +114 -0
  459. package/src/pattern/edit.js +35 -3
  460. package/src/pattern/index.php +16 -0
  461. package/src/pattern/recursion-detector.js +145 -0
  462. package/src/pattern/test/index.js +74 -0
  463. package/src/post-featured-image/block.json +4 -0
  464. package/src/post-featured-image/edit.js +32 -1
  465. package/src/post-featured-image/index.php +31 -0
  466. package/src/post-title/block.json +1 -3
  467. package/src/preformatted/block.json +2 -3
  468. package/src/pullquote/block.json +5 -7
  469. package/src/query/edit/inspector-controls/index.js +2 -0
  470. package/src/query/edit/inspector-controls/taxonomy-controls.js +2 -0
  471. package/src/query-pagination-numbers/block.json +1 -1
  472. package/src/query-title/block.json +1 -3
  473. package/src/quote/block.json +3 -5
  474. package/src/quote/transforms.js +12 -11
  475. package/src/search/block.json +0 -4
  476. package/src/search/edit.js +2 -8
  477. package/src/search/index.php +3 -7
  478. package/src/search/style.scss +27 -29
  479. package/src/site-logo/edit.js +3 -4
  480. package/src/site-title/block.json +1 -5
  481. package/src/social-link/icons/gravatar.js +10 -0
  482. package/src/social-link/icons/index.js +1 -0
  483. package/src/social-link/index.php +5 -1
  484. package/src/social-link/socials-with-bg.scss +5 -0
  485. package/src/social-link/socials-without-bg.scss +4 -0
  486. package/src/social-link/variations.js +7 -0
  487. package/src/social-links/style.scss +14 -8
  488. package/src/spacer/edit.native.js +4 -2
  489. package/src/table/block.json +9 -10
  490. package/src/table/edit.js +3 -1
  491. package/src/table/editor.scss +1 -17
  492. package/src/table-of-contents/edit.js +1 -1
  493. package/src/table-of-contents/index.js +5 -1
  494. package/src/tag-cloud/edit.js +7 -7
  495. package/src/template-part/index.php +6 -0
  496. package/src/utils/caption.js +108 -0
  497. package/src/utils/constants.js +8 -0
  498. package/src/utils/remove-anchor-tag.js +2 -1
  499. package/src/verse/block.json +3 -5
  500. package/src/video/block.json +2 -2
  501. package/src/video/edit.js +40 -100
  502. package/src/video/edit.native.js +2 -1
  503. package/build/block/edit.native.js.map +0 -1
  504. package/build/table-of-contents/icon.js +0 -22
  505. package/build/table-of-contents/icon.js.map +0 -1
  506. package/build-module/block/edit.native.js.map +0 -1
  507. package/build-module/table-of-contents/icon.js +0 -15
  508. package/build-module/table-of-contents/icon.js.map +0 -1
  509. package/src/table-of-contents/icon.js +0 -18
@@ -15,41 +15,24 @@ import {
15
15
  __experimentalToolsPanelItem as ToolsPanelItem,
16
16
  __experimentalUseCustomUnits as useCustomUnits,
17
17
  } from '@wordpress/components';
18
- import { useViewportMatch, usePrevious } from '@wordpress/compose';
18
+ import { useViewportMatch } from '@wordpress/compose';
19
19
  import { useSelect, useDispatch } from '@wordpress/data';
20
20
  import {
21
21
  BlockControls,
22
22
  InspectorControls,
23
- RichText,
24
23
  __experimentalImageURLInputUI as ImageURLInputUI,
25
24
  MediaReplaceFlow,
26
25
  store as blockEditorStore,
27
26
  useSettings,
28
27
  __experimentalImageEditor as ImageEditor,
29
- __experimentalGetElementClassName,
30
28
  __experimentalUseBorderProps as useBorderProps,
31
29
  privateApis as blockEditorPrivateApis,
32
30
  } from '@wordpress/block-editor';
33
- import {
34
- useEffect,
35
- useMemo,
36
- useState,
37
- useRef,
38
- useCallback,
39
- } from '@wordpress/element';
31
+ import { useEffect, useMemo, useState, useRef } from '@wordpress/element';
40
32
  import { __, _x, sprintf, isRTL } from '@wordpress/i18n';
41
33
  import { getFilename } from '@wordpress/url';
42
- import {
43
- createBlock,
44
- getDefaultBlockName,
45
- switchToBlockType,
46
- } from '@wordpress/blocks';
47
- import {
48
- crop,
49
- overlayText,
50
- upload,
51
- caption as captionIcon,
52
- } from '@wordpress/icons';
34
+ import { switchToBlockType } from '@wordpress/blocks';
35
+ import { crop, overlayText, upload } from '@wordpress/icons';
53
36
  import { store as noticesStore } from '@wordpress/notices';
54
37
  import { store as coreStore } from '@wordpress/core-data';
55
38
 
@@ -60,10 +43,12 @@ import { unlock } from '../lock-unlock';
60
43
  import { createUpgradedEmbedBlock } from '../embed/util';
61
44
  import useClientWidth from './use-client-width';
62
45
  import { isExternalImage } from './edit';
46
+ import { Caption } from '../utils/caption';
63
47
 
64
48
  /**
65
49
  * Module constants
66
50
  */
51
+ import { TOOLSPANEL_DROPDOWNMENU_PROPS } from '../utils/constants';
67
52
  import { MIN_SIZE, ALLOWED_MEDIA_TYPES } from './constants';
68
53
  import { evalAspectRatio } from './utils';
69
54
 
@@ -125,7 +110,6 @@ export default function Image( {
125
110
  const {
126
111
  url = '',
127
112
  alt,
128
- caption,
129
113
  align,
130
114
  id,
131
115
  href,
@@ -147,22 +131,52 @@ export default function Image( {
147
131
  const numericHeight = height ? parseInt( height, 10 ) : undefined;
148
132
 
149
133
  const imageRef = useRef();
150
- const prevCaption = usePrevious( caption );
151
- const [ showCaption, setShowCaption ] = useState( !! caption );
152
134
  const { allowResize = true } = context;
153
135
  const { getBlock } = useSelect( blockEditorStore );
154
136
 
155
- const { image, multiImageSelection } = useSelect(
137
+ const { image } = useSelect(
156
138
  ( select ) => {
157
139
  const { getMedia } = select( coreStore );
158
- const { getMultiSelectedBlockClientIds, getBlockName } =
159
- select( blockEditorStore );
160
- const multiSelectedClientIds = getMultiSelectedBlockClientIds();
161
140
  return {
162
141
  image:
163
142
  id && isSelected
164
143
  ? getMedia( id, { context: 'view' } )
165
144
  : null,
145
+ };
146
+ },
147
+ [ id, isSelected ]
148
+ );
149
+
150
+ const {
151
+ canInsertCover,
152
+ imageEditing,
153
+ imageSizes,
154
+ maxWidth,
155
+ mediaUpload,
156
+ multiImageSelection,
157
+ } = useSelect(
158
+ ( select ) => {
159
+ const {
160
+ getBlockRootClientId,
161
+ getMultiSelectedBlockClientIds,
162
+ getBlockName,
163
+ getSettings,
164
+ canInsertBlockType,
165
+ } = select( blockEditorStore );
166
+
167
+ const rootClientId = getBlockRootClientId( clientId );
168
+ const settings = getSettings();
169
+ const multiSelectedClientIds = getMultiSelectedBlockClientIds();
170
+
171
+ return {
172
+ imageEditing: settings.imageEditing,
173
+ imageSizes: settings.imageSizes,
174
+ maxWidth: settings.maxWidth,
175
+ mediaUpload: settings.mediaUpload,
176
+ canInsertCover: canInsertBlockType(
177
+ 'core/cover',
178
+ rootClientId
179
+ ),
166
180
  multiImageSelection:
167
181
  multiSelectedClientIds.length &&
168
182
  multiSelectedClientIds.every(
@@ -171,33 +185,8 @@ export default function Image( {
171
185
  ),
172
186
  };
173
187
  },
174
- [ id, isSelected ]
188
+ [ clientId ]
175
189
  );
176
- const { canInsertCover, imageEditing, imageSizes, maxWidth, mediaUpload } =
177
- useSelect(
178
- ( select ) => {
179
- const {
180
- getBlockRootClientId,
181
- getSettings,
182
- canInsertBlockType,
183
- } = select( blockEditorStore );
184
-
185
- const rootClientId = getBlockRootClientId( clientId );
186
- const settings = getSettings();
187
-
188
- return {
189
- imageEditing: settings.imageEditing,
190
- imageSizes: settings.imageSizes,
191
- maxWidth: settings.maxWidth,
192
- mediaUpload: settings.mediaUpload,
193
- canInsertCover: canInsertBlockType(
194
- 'core/cover',
195
- rootClientId
196
- ),
197
- };
198
- },
199
- [ clientId ]
200
- );
201
190
 
202
191
  const { replaceBlocks, toggleSelection } = useDispatch( blockEditorStore );
203
192
  const { createErrorNotice, createSuccessNotice } =
@@ -215,7 +204,8 @@ export default function Image( {
215
204
  const isResizable =
216
205
  allowResize &&
217
206
  hasNonContentControls &&
218
- ! ( isWideAligned && isLargeViewport );
207
+ ! isWideAligned &&
208
+ isLargeViewport;
219
209
  const imageSizeOptions = imageSizes
220
210
  .filter(
221
211
  ( { slug } ) => image?.media_details?.sizes?.[ slug ]?.source_url
@@ -247,24 +237,6 @@ export default function Image( {
247
237
  .catch( () => {} );
248
238
  }, [ id, url, isSelected, externalBlob, canUploadMedia ] );
249
239
 
250
- // We need to show the caption when changes come from
251
- // history navigation(undo/redo).
252
- useEffect( () => {
253
- if ( caption && ! prevCaption ) {
254
- setShowCaption( true );
255
- }
256
- }, [ caption, prevCaption ] );
257
-
258
- // Focus the caption when we click to add one.
259
- const captionRef = useCallback(
260
- ( node ) => {
261
- if ( node && ! caption ) {
262
- node.focus();
263
- }
264
- },
265
- [ caption ]
266
- );
267
-
268
240
  // Get naturalWidth and naturalHeight from image ref, and fall back to loaded natural
269
241
  // width and height. This resolves an issue in Safari where the loaded natural
270
242
  // width and height is otherwise lost when switching between alignments.
@@ -355,11 +327,8 @@ export default function Image( {
355
327
  useEffect( () => {
356
328
  if ( ! isSelected ) {
357
329
  setIsEditingImage( false );
358
- if ( ! caption ) {
359
- setShowCaption( false );
360
- }
361
330
  }
362
- }, [ isSelected, caption ] );
331
+ }, [ isSelected ] );
363
332
 
364
333
  const canEditImage = id && naturalWidth && naturalHeight && imageEditing;
365
334
  const allowCrop = ! multiImageSelection && canEditImage && ! isEditingImage;
@@ -420,6 +389,7 @@ export default function Image( {
420
389
 
421
390
  const resetAll = () => {
422
391
  setAttributes( {
392
+ alt: undefined,
423
393
  width: undefined,
424
394
  height: undefined,
425
395
  scale: undefined,
@@ -430,7 +400,11 @@ export default function Image( {
430
400
 
431
401
  const sizeControls = (
432
402
  <InspectorControls>
433
- <ToolsPanel label={ __( 'Settings' ) } resetAll={ resetAll }>
403
+ <ToolsPanel
404
+ label={ __( 'Settings' ) }
405
+ resetAll={ resetAll }
406
+ dropdownMenuProps={ TOOLSPANEL_DROPDOWNMENU_PROPS }
407
+ >
434
408
  { isResizable && dimensionsControl }
435
409
  </ToolsPanel>
436
410
  </InspectorControls>
@@ -439,23 +413,6 @@ export default function Image( {
439
413
  const controls = (
440
414
  <>
441
415
  <BlockControls group="block">
442
- { hasNonContentControls && (
443
- <ToolbarButton
444
- onClick={ () => {
445
- setShowCaption( ! showCaption );
446
- if ( showCaption && caption ) {
447
- setAttributes( { caption: undefined } );
448
- }
449
- } }
450
- icon={ captionIcon }
451
- isPressed={ showCaption }
452
- label={
453
- showCaption
454
- ? __( 'Remove caption' )
455
- : __( 'Add caption' )
456
- }
457
- />
458
- ) }
459
416
  { ! multiImageSelection && ! isEditingImage && (
460
417
  <ImageURLInputUI
461
418
  url={ href || '' }
@@ -502,25 +459,29 @@ export default function Image( {
502
459
  <ToolbarButton
503
460
  onClick={ uploadExternal }
504
461
  icon={ upload }
505
- label={ __( 'Upload external image' ) }
462
+ label={ __( 'Upload image to media library' ) }
506
463
  />
507
464
  </ToolbarGroup>
508
465
  </BlockControls>
509
466
  ) }
510
467
  <InspectorControls>
511
- <ToolsPanel label={ __( 'Settings' ) } resetAll={ resetAll }>
468
+ <ToolsPanel
469
+ label={ __( 'Settings' ) }
470
+ resetAll={ resetAll }
471
+ dropdownMenuProps={ TOOLSPANEL_DROPDOWNMENU_PROPS }
472
+ >
512
473
  { ! multiImageSelection && (
513
474
  <ToolsPanelItem
514
475
  label={ __( 'Alternative text' ) }
515
476
  isShownByDefault={ true }
516
- hasValue={ () => alt !== '' }
477
+ hasValue={ () => !! alt }
517
478
  onDeselect={ () =>
518
479
  setAttributes( { alt: undefined } )
519
480
  }
520
481
  >
521
482
  <TextareaControl
522
483
  label={ __( 'Alternative text' ) }
523
- value={ alt }
484
+ value={ alt || '' }
524
485
  onChange={ updateAlt }
525
486
  help={
526
487
  <>
@@ -538,11 +499,13 @@ export default function Image( {
538
499
  </ToolsPanelItem>
539
500
  ) }
540
501
  { isResizable && dimensionsControl }
541
- <ResolutionTool
542
- value={ sizeSlug }
543
- onChange={ updateImage }
544
- options={ imageSizeOptions }
545
- />
502
+ { !! imageSizeOptions.length && (
503
+ <ResolutionTool
504
+ value={ sizeSlug }
505
+ onChange={ updateImage }
506
+ options={ imageSizeOptions }
507
+ />
508
+ ) }
546
509
  { showLightboxToggle && (
547
510
  <ToolsPanelItem
548
511
  hasValue={ () => !! lightbox }
@@ -793,29 +756,16 @@ export default function Image( {
793
756
  which causes duplicated image upload. */ }
794
757
  { ! temporaryURL && controls }
795
758
  { img }
796
- { showCaption &&
797
- ( ! RichText.isEmpty( caption ) || isSelected ) && (
798
- <RichText
799
- identifier="caption"
800
- className={ __experimentalGetElementClassName(
801
- 'caption'
802
- ) }
803
- ref={ captionRef }
804
- tagName="figcaption"
805
- aria-label={ __( 'Image caption text' ) }
806
- placeholder={ __( 'Add caption' ) }
807
- value={ caption }
808
- onChange={ ( value ) =>
809
- setAttributes( { caption: value } )
810
- }
811
- inlineToolbar
812
- __unstableOnSplitAtEnd={ () =>
813
- insertBlocksAfter(
814
- createBlock( getDefaultBlockName() )
815
- )
816
- }
817
- />
818
- ) }
759
+ <Caption
760
+ attributes={ attributes }
761
+ setAttributes={ setAttributes }
762
+ isSelected={ isSelected }
763
+ insertBlocksAfter={ insertBlocksAfter }
764
+ label={ __( 'Image caption text' ) }
765
+ showToolbarButton={
766
+ ! multiImageSelection && hasNonContentControls
767
+ }
768
+ />
819
769
  </>
820
770
  );
821
771
  }
@@ -97,12 +97,6 @@ function block_core_image_get_lightbox_settings( $block ) {
97
97
  // Get the lightbox setting from the block attributes.
98
98
  if ( isset( $block['attrs']['lightbox'] ) ) {
99
99
  $lightbox_settings = $block['attrs']['lightbox'];
100
- // If the lightbox setting is not set in the block attributes,
101
- // check the legacy lightbox settings that are set using the
102
- // `gutenberg_should_render_lightbox` filter.
103
- // We can remove this elseif statement when the legacy lightbox settings are removed.
104
- } elseif ( isset( $block['legacyLightboxSettings'] ) ) {
105
- $lightbox_settings = $block['legacyLightboxSettings'];
106
100
  }
107
101
 
108
102
  if ( ! isset( $lightbox_settings ) ) {
@@ -239,6 +233,7 @@ function block_core_image_render_lightbox( $block_content, $block ) {
239
233
  type="button"
240
234
  aria-haspopup="dialog"
241
235
  aria-label="' . esc_attr( $aria_label ) . '"
236
+ data-wp-init="callbacks.initTriggerButton"
242
237
  data-wp-on--click="actions.showLightbox"
243
238
  data-wp-style--right="context.imageButtonRight"
244
239
  data-wp-style--top="context.imageButtonTop"
package/src/image/save.js CHANGED
@@ -36,7 +36,9 @@ export default function save( { attributes } ) {
36
36
  const borderProps = getBorderClassesAndStyles( attributes );
37
37
 
38
38
  const classes = classnames( {
39
- [ `align${ align }` ]: align,
39
+ // All other align classes are handled by block supports.
40
+ // `{ align: 'none' }` is unique to transforms for the image block.
41
+ alignnone: 'none' === align,
40
42
  [ `size-${ sizeSlug }` ]: sizeSlug,
41
43
  'is-resized': width || height,
42
44
  'has-custom-border':
package/src/image/view.js CHANGED
@@ -230,13 +230,16 @@ const { state, actions, callbacks } = store( 'core/image', {
230
230
  const ctx = getContext();
231
231
  const { ref } = getElement();
232
232
  ctx.imageRef = ref;
233
- ctx.lightboxTriggerRef =
234
- ref.parentElement.querySelector( '.lightbox-trigger' );
235
233
  if ( ref.complete ) {
236
234
  ctx.imageLoaded = true;
237
235
  ctx.imageCurrentSrc = ref.currentSrc;
238
236
  }
239
237
  },
238
+ initTriggerButton() {
239
+ const ctx = getContext();
240
+ const { ref } = getElement();
241
+ ctx.lightboxTriggerRef = ref;
242
+ },
240
243
  initLightbox() {
241
244
  const ctx = getContext();
242
245
  const { ref } = getElement();
package/src/list/edit.js CHANGED
@@ -68,48 +68,40 @@ function useMigrateOnLoad( attributes, clientId ) {
68
68
  }
69
69
 
70
70
  function useOutdentList( clientId ) {
71
- const { canOutdent } = useSelect(
72
- ( innerSelect ) => {
73
- const { getBlockRootClientId, getBlock } =
74
- innerSelect( blockEditorStore );
75
- const parentId = getBlockRootClientId( clientId );
76
- return {
77
- canOutdent:
78
- !! parentId &&
79
- getBlock( parentId ).name === 'core/list-item',
80
- };
81
- },
82
- [ clientId ]
83
- );
84
71
  const { replaceBlocks, selectionChange } = useDispatch( blockEditorStore );
85
72
  const { getBlockRootClientId, getBlockAttributes, getBlock } =
86
73
  useSelect( blockEditorStore );
87
74
 
88
- return [
89
- canOutdent,
90
- useCallback( () => {
91
- const parentBlockId = getBlockRootClientId( clientId );
92
- const parentBlockAttributes = getBlockAttributes( parentBlockId );
93
- // Create a new parent block without the inner blocks.
94
- const newParentBlock = createBlock(
95
- 'core/list-item',
96
- parentBlockAttributes
97
- );
98
- const { innerBlocks } = getBlock( clientId );
99
- // Replace the parent block with a new parent block without inner blocks,
100
- // and make the inner blocks siblings of the parent.
101
- replaceBlocks(
102
- [ parentBlockId ],
103
- [ newParentBlock, ...innerBlocks ]
104
- );
105
- // Select the last child of the list being outdent.
106
- selectionChange( innerBlocks[ innerBlocks.length - 1 ].clientId );
107
- }, [ clientId ] ),
108
- ];
75
+ return useCallback( () => {
76
+ const parentBlockId = getBlockRootClientId( clientId );
77
+ const parentBlockAttributes = getBlockAttributes( parentBlockId );
78
+ // Create a new parent block without the inner blocks.
79
+ const newParentBlock = createBlock(
80
+ 'core/list-item',
81
+ parentBlockAttributes
82
+ );
83
+ const { innerBlocks } = getBlock( clientId );
84
+ // Replace the parent block with a new parent block without inner blocks,
85
+ // and make the inner blocks siblings of the parent.
86
+ replaceBlocks( [ parentBlockId ], [ newParentBlock, ...innerBlocks ] );
87
+ // Select the last child of the list being outdent.
88
+ selectionChange( innerBlocks[ innerBlocks.length - 1 ].clientId );
89
+ }, [ clientId ] );
109
90
  }
110
91
 
111
92
  function IndentUI( { clientId } ) {
112
- const [ canOutdent, outdentList ] = useOutdentList( clientId );
93
+ const outdentList = useOutdentList( clientId );
94
+ const canOutdent = useSelect(
95
+ ( select ) => {
96
+ const { getBlockRootClientId, getBlockName } =
97
+ select( blockEditorStore );
98
+ return (
99
+ getBlockName( getBlockRootClientId( clientId ) ) ===
100
+ 'core/list-item'
101
+ );
102
+ },
103
+ [ clientId ]
104
+ );
113
105
  return (
114
106
  <>
115
107
  <ToolbarButton
@@ -12,16 +12,23 @@
12
12
  "type": "string"
13
13
  },
14
14
  "content": {
15
- "type": "string",
16
- "source": "html",
15
+ "type": "rich-text",
16
+ "source": "rich-text",
17
17
  "selector": "li",
18
- "default": "",
19
18
  "__experimentalRole": "content"
20
19
  }
21
20
  },
22
21
  "supports": {
23
22
  "className": false,
24
23
  "__experimentalSelector": "li",
24
+ "spacing": {
25
+ "margin": true,
26
+ "padding": true,
27
+ "__experimentalDefaultControls": {
28
+ "margin": false,
29
+ "padding": false
30
+ }
31
+ },
25
32
  "typography": {
26
33
  "fontSize": true,
27
34
  "lineHeight": true,
@@ -6,6 +6,7 @@ import {
6
6
  useBlockProps,
7
7
  useInnerBlocksProps,
8
8
  BlockControls,
9
+ store as blockEditorStore,
9
10
  } from '@wordpress/block-editor';
10
11
  import { isRTL, __ } from '@wordpress/i18n';
11
12
  import { ToolbarButton } from '@wordpress/components';
@@ -16,6 +17,7 @@ import {
16
17
  formatIndent,
17
18
  } from '@wordpress/icons';
18
19
  import { useMergeRefs } from '@wordpress/compose';
20
+ import { useSelect } from '@wordpress/data';
19
21
 
20
22
  /**
21
23
  * Internal dependencies
@@ -32,8 +34,22 @@ import {
32
34
  import { convertToListItems } from './utils';
33
35
 
34
36
  export function IndentUI( { clientId } ) {
35
- const [ canIndent, indentListItem ] = useIndentListItem( clientId );
36
- const [ canOutdent, outdentListItem ] = useOutdentListItem( clientId );
37
+ const indentListItem = useIndentListItem( clientId );
38
+ const outdentListItem = useOutdentListItem();
39
+ const { canIndent, canOutdent } = useSelect(
40
+ ( select ) => {
41
+ const { getBlockIndex, getBlockRootClientId, getBlockName } =
42
+ select( blockEditorStore );
43
+ return {
44
+ canIndent: getBlockIndex( clientId ) > 0,
45
+ canOutdent:
46
+ getBlockName(
47
+ getBlockRootClientId( getBlockRootClientId( clientId ) )
48
+ ) === 'core/list-item',
49
+ };
50
+ },
51
+ [ clientId ]
52
+ );
37
53
 
38
54
  return (
39
55
  <>
@@ -19,71 +19,72 @@ import useOutdentListItem from './use-outdent-list-item';
19
19
 
20
20
  export default function useEnter( props ) {
21
21
  const { replaceBlocks, selectionChange } = useDispatch( blockEditorStore );
22
- const { getBlock, getBlockRootClientId, getBlockIndex } =
22
+ const { getBlock, getBlockRootClientId, getBlockIndex, getBlockName } =
23
23
  useSelect( blockEditorStore );
24
24
  const propsRef = useRef( props );
25
25
  propsRef.current = props;
26
- const [ canOutdent, outdentListItem ] = useOutdentListItem(
27
- propsRef.current.clientId
28
- );
29
- return useRefEffect(
30
- ( element ) => {
31
- function onKeyDown( event ) {
32
- if ( event.defaultPrevented || event.keyCode !== ENTER ) {
33
- return;
34
- }
35
- const { content, clientId } = propsRef.current;
36
- if ( content.length ) {
37
- return;
38
- }
39
- event.preventDefault();
40
- if ( canOutdent ) {
41
- outdentListItem();
42
- return;
43
- }
44
- // Here we are in top level list so we need to split.
45
- const topParentListBlock = getBlock(
46
- getBlockRootClientId( clientId )
47
- );
48
- const blockIndex = getBlockIndex( clientId );
49
- const head = cloneBlock( {
50
- ...topParentListBlock,
51
- innerBlocks: topParentListBlock.innerBlocks.slice(
52
- 0,
53
- blockIndex
54
- ),
55
- } );
56
- const middle = createBlock( getDefaultBlockName() );
57
- // Last list item might contain a `list` block innerBlock
58
- // In that case append remaining innerBlocks blocks.
59
- const after = [
60
- ...( topParentListBlock.innerBlocks[ blockIndex ]
61
- .innerBlocks[ 0 ]?.innerBlocks || [] ),
62
- ...topParentListBlock.innerBlocks.slice( blockIndex + 1 ),
63
- ];
64
- const tail = after.length
65
- ? [
66
- cloneBlock( {
67
- ...topParentListBlock,
68
- innerBlocks: after,
69
- } ),
70
- ]
71
- : [];
72
- replaceBlocks(
73
- topParentListBlock.clientId,
74
- [ head, middle, ...tail ],
75
- 1
76
- );
77
- // We manually change the selection here because we are replacing
78
- // a different block than the selected one.
79
- selectionChange( middle.clientId );
26
+ const outdentListItem = useOutdentListItem();
27
+ return useRefEffect( ( element ) => {
28
+ function onKeyDown( event ) {
29
+ if ( event.defaultPrevented || event.keyCode !== ENTER ) {
30
+ return;
80
31
  }
32
+ const { content, clientId } = propsRef.current;
33
+ if ( content.length ) {
34
+ return;
35
+ }
36
+ event.preventDefault();
37
+ const canOutdent =
38
+ getBlockName(
39
+ getBlockRootClientId(
40
+ getBlockRootClientId( propsRef.current.clientId )
41
+ )
42
+ ) === 'core/list-item';
43
+ if ( canOutdent ) {
44
+ outdentListItem();
45
+ return;
46
+ }
47
+ // Here we are in top level list so we need to split.
48
+ const topParentListBlock = getBlock(
49
+ getBlockRootClientId( clientId )
50
+ );
51
+ const blockIndex = getBlockIndex( clientId );
52
+ const head = cloneBlock( {
53
+ ...topParentListBlock,
54
+ innerBlocks: topParentListBlock.innerBlocks.slice(
55
+ 0,
56
+ blockIndex
57
+ ),
58
+ } );
59
+ const middle = createBlock( getDefaultBlockName() );
60
+ // Last list item might contain a `list` block innerBlock
61
+ // In that case append remaining innerBlocks blocks.
62
+ const after = [
63
+ ...( topParentListBlock.innerBlocks[ blockIndex ]
64
+ .innerBlocks[ 0 ]?.innerBlocks || [] ),
65
+ ...topParentListBlock.innerBlocks.slice( blockIndex + 1 ),
66
+ ];
67
+ const tail = after.length
68
+ ? [
69
+ cloneBlock( {
70
+ ...topParentListBlock,
71
+ innerBlocks: after,
72
+ } ),
73
+ ]
74
+ : [];
75
+ replaceBlocks(
76
+ topParentListBlock.clientId,
77
+ [ head, middle, ...tail ],
78
+ 1
79
+ );
80
+ // We manually change the selection here because we are replacing
81
+ // a different block than the selected one.
82
+ selectionChange( middle.clientId );
83
+ }
81
84
 
82
- element.addEventListener( 'keydown', onKeyDown );
83
- return () => {
84
- element.removeEventListener( 'keydown', onKeyDown );
85
- };
86
- },
87
- [ canOutdent ]
88
- );
85
+ element.addEventListener( 'keydown', onKeyDown );
86
+ return () => {
87
+ element.removeEventListener( 'keydown', onKeyDown );
88
+ };
89
+ }, [] );
89
90
  }