@wordpress/block-library 7.10.0 → 7.11.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 (374) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/button/edit.js +2 -1
  3. package/build/button/edit.js.map +1 -1
  4. package/build/buttons/edit.js +1 -1
  5. package/build/buttons/edit.js.map +1 -1
  6. package/build/columns/edit.native.js +1 -1
  7. package/build/columns/edit.native.js.map +1 -1
  8. package/build/comments/edit/comments-legacy.js +73 -0
  9. package/build/comments/edit/comments-legacy.js.map +1 -0
  10. package/build/comments/{edit.js → edit/index.js} +17 -38
  11. package/build/comments/edit/index.js.map +1 -0
  12. package/build/comments/edit/placeholder.js +117 -0
  13. package/build/comments/edit/placeholder.js.map +1 -0
  14. package/build/comments/edit/template.js +39 -0
  15. package/build/comments/edit/template.js.map +1 -0
  16. package/build/comments/index.js +6 -1
  17. package/build/comments/index.js.map +1 -1
  18. package/build/comments/save.js +12 -4
  19. package/build/comments/save.js.map +1 -1
  20. package/build/cover/transforms.js +3 -2
  21. package/build/cover/transforms.js.map +1 -1
  22. package/build/embed/embed-placeholder.native.js +1 -3
  23. package/build/embed/embed-placeholder.native.js.map +1 -1
  24. package/build/gallery/edit.js +2 -2
  25. package/build/gallery/edit.js.map +1 -1
  26. package/build/gallery/use-get-media.native.js +59 -0
  27. package/build/gallery/use-get-media.native.js.map +1 -0
  28. package/build/group/index.js +1 -0
  29. package/build/group/index.js.map +1 -1
  30. package/build/group/variations.js +1 -1
  31. package/build/group/variations.js.map +1 -1
  32. package/build/image/deprecated.js +77 -9
  33. package/build/image/deprecated.js.map +1 -1
  34. package/build/image/edit.js +3 -1
  35. package/build/image/edit.js.map +1 -1
  36. package/build/image/edit.native.js +18 -8
  37. package/build/image/edit.native.js.map +1 -1
  38. package/build/image/image.js +27 -20
  39. package/build/image/image.js.map +1 -1
  40. package/build/image/index.js +7 -1
  41. package/build/image/index.js.map +1 -1
  42. package/build/image/save.js +8 -2
  43. package/build/image/save.js.map +1 -1
  44. package/build/index.js +1 -3
  45. package/build/index.js.map +1 -1
  46. package/build/index.native.js +3 -13
  47. package/build/index.native.js.map +1 -1
  48. package/build/list/transforms.js +4 -63
  49. package/build/list/transforms.js.map +1 -1
  50. package/build/list/v2/transforms.js +0 -27
  51. package/build/list/v2/transforms.js.map +1 -1
  52. package/build/list-item/edit.js +14 -9
  53. package/build/list-item/edit.js.map +1 -1
  54. package/build/list-item/hooks/index.js +8 -8
  55. package/build/list-item/hooks/index.js.map +1 -1
  56. package/build/list-item/hooks/use-merge.js +174 -0
  57. package/build/list-item/hooks/use-merge.js.map +1 -0
  58. package/build/list-item/hooks/use-outdent-list-item.js +86 -50
  59. package/build/list-item/hooks/use-outdent-list-item.js.map +1 -1
  60. package/build/list-item/utils.js +125 -1
  61. package/build/list-item/utils.js.map +1 -1
  62. package/build/media-text/deprecated.js +134 -7
  63. package/build/media-text/deprecated.js.map +1 -1
  64. package/build/media-text/edit.js +2 -2
  65. package/build/media-text/edit.js.map +1 -1
  66. package/build/media-text/save.js +13 -0
  67. package/build/media-text/save.js.map +1 -1
  68. package/build/more/save.js +1 -7
  69. package/build/more/save.js.map +1 -1
  70. package/build/navigation-link/edit.js +5 -4
  71. package/build/navigation-link/edit.js.map +1 -1
  72. package/build/navigation-submenu/edit.js +2 -1
  73. package/build/navigation-submenu/edit.js.map +1 -1
  74. package/build/page-list/edit.js +8 -1
  75. package/build/page-list/edit.js.map +1 -1
  76. package/build/paragraph/edit.js +7 -11
  77. package/build/paragraph/edit.js.map +1 -1
  78. package/build/post-comments-form/edit.js +4 -45
  79. package/build/post-comments-form/edit.js.map +1 -1
  80. package/build/post-comments-form/form.js +47 -3
  81. package/build/post-comments-form/form.js.map +1 -1
  82. package/build/post-terms/edit.js +3 -2
  83. package/build/post-terms/edit.js.map +1 -1
  84. package/build/query-no-results/edit.js +1 -1
  85. package/build/query-no-results/edit.js.map +1 -1
  86. package/build/query-pagination-next/edit.js +2 -1
  87. package/build/query-pagination-next/edit.js.map +1 -1
  88. package/build/query-pagination-previous/edit.js +2 -1
  89. package/build/query-pagination-previous/edit.js.map +1 -1
  90. package/build/quote/deprecated.js +168 -36
  91. package/build/quote/deprecated.js.map +1 -1
  92. package/build/quote/edit.js +76 -39
  93. package/build/quote/edit.js.map +1 -1
  94. package/build/quote/index.js +9 -45
  95. package/build/quote/index.js.map +1 -1
  96. package/build/quote/save.js +1 -5
  97. package/build/quote/save.js.map +1 -1
  98. package/build/quote/transforms.js +110 -158
  99. package/build/quote/transforms.js.map +1 -1
  100. package/build/social-link/icons/index.js +13 -0
  101. package/build/social-link/icons/index.js.map +1 -1
  102. package/build/social-link/icons/whatsapp.js +25 -0
  103. package/build/social-link/icons/whatsapp.js.map +1 -0
  104. package/build/social-link/variations.js +7 -0
  105. package/build/social-link/variations.js.map +1 -1
  106. package/build/template-part/edit/index.js +17 -8
  107. package/build/template-part/edit/index.js.map +1 -1
  108. package/build/template-part/edit/selection-modal.js +33 -13
  109. package/build/template-part/edit/selection-modal.js.map +1 -1
  110. package/build/template-part/edit/utils/search.js +94 -0
  111. package/build/template-part/edit/utils/search.js.map +1 -0
  112. package/build-module/button/edit.js +2 -1
  113. package/build-module/button/edit.js.map +1 -1
  114. package/build-module/buttons/edit.js +2 -2
  115. package/build-module/buttons/edit.js.map +1 -1
  116. package/build-module/columns/edit.native.js +2 -2
  117. package/build-module/columns/edit.native.js.map +1 -1
  118. package/build-module/comments/edit/comments-legacy.js +59 -0
  119. package/build-module/comments/edit/comments-legacy.js.map +1 -0
  120. package/build-module/comments/edit/index.js +37 -0
  121. package/build-module/comments/edit/index.js.map +1 -0
  122. package/build-module/comments/edit/placeholder.js +102 -0
  123. package/build-module/comments/edit/placeholder.js.map +1 -0
  124. package/build-module/comments/edit/template.js +32 -0
  125. package/build-module/comments/edit/template.js.map +1 -0
  126. package/build-module/comments/index.js +6 -1
  127. package/build-module/comments/index.js.map +1 -1
  128. package/build-module/comments/save.js +9 -4
  129. package/build-module/comments/save.js.map +1 -1
  130. package/build-module/cover/transforms.js +3 -2
  131. package/build-module/cover/transforms.js.map +1 -1
  132. package/build-module/embed/embed-placeholder.native.js +1 -2
  133. package/build-module/embed/embed-placeholder.native.js.map +1 -1
  134. package/build-module/gallery/edit.js +2 -2
  135. package/build-module/gallery/edit.js.map +1 -1
  136. package/build-module/gallery/use-get-media.native.js +50 -0
  137. package/build-module/gallery/use-get-media.native.js.map +1 -0
  138. package/build-module/group/index.js +1 -0
  139. package/build-module/group/index.js.map +1 -1
  140. package/build-module/group/variations.js +2 -2
  141. package/build-module/group/variations.js.map +1 -1
  142. package/build-module/image/deprecated.js +77 -9
  143. package/build-module/image/deprecated.js.map +1 -1
  144. package/build-module/image/edit.js +5 -3
  145. package/build-module/image/edit.js.map +1 -1
  146. package/build-module/image/edit.native.js +18 -8
  147. package/build-module/image/edit.native.js.map +1 -1
  148. package/build-module/image/image.js +29 -22
  149. package/build-module/image/image.js.map +1 -1
  150. package/build-module/image/index.js +7 -1
  151. package/build-module/image/index.js.map +1 -1
  152. package/build-module/image/save.js +9 -3
  153. package/build-module/image/save.js.map +1 -1
  154. package/build-module/index.js +1 -2
  155. package/build-module/index.js.map +1 -1
  156. package/build-module/index.native.js +3 -13
  157. package/build-module/index.native.js.map +1 -1
  158. package/build-module/list/transforms.js +4 -63
  159. package/build-module/list/transforms.js.map +1 -1
  160. package/build-module/list/v2/transforms.js +2 -29
  161. package/build-module/list/v2/transforms.js.map +1 -1
  162. package/build-module/list-item/edit.js +14 -10
  163. package/build-module/list-item/edit.js.map +1 -1
  164. package/build-module/list-item/hooks/index.js +1 -1
  165. package/build-module/list-item/hooks/index.js.map +1 -1
  166. package/build-module/list-item/hooks/use-merge.js +160 -0
  167. package/build-module/list-item/hooks/use-merge.js.map +1 -0
  168. package/build-module/list-item/hooks/use-outdent-list-item.js +82 -46
  169. package/build-module/list-item/hooks/use-outdent-list-item.js.map +1 -1
  170. package/build-module/list-item/utils.js +123 -2
  171. package/build-module/list-item/utils.js.map +1 -1
  172. package/build-module/media-text/deprecated.js +134 -8
  173. package/build-module/media-text/deprecated.js.map +1 -1
  174. package/build-module/media-text/edit.js +2 -2
  175. package/build-module/media-text/edit.js.map +1 -1
  176. package/build-module/media-text/save.js +13 -0
  177. package/build-module/media-text/save.js.map +1 -1
  178. package/build-module/more/save.js +1 -6
  179. package/build-module/more/save.js.map +1 -1
  180. package/build-module/navigation-link/edit.js +5 -4
  181. package/build-module/navigation-link/edit.js.map +1 -1
  182. package/build-module/navigation-submenu/edit.js +2 -1
  183. package/build-module/navigation-submenu/edit.js.map +1 -1
  184. package/build-module/page-list/edit.js +8 -1
  185. package/build-module/page-list/edit.js.map +1 -1
  186. package/build-module/paragraph/edit.js +8 -12
  187. package/build-module/paragraph/edit.js.map +1 -1
  188. package/build-module/post-comments-form/edit.js +5 -42
  189. package/build-module/post-comments-form/edit.js.map +1 -1
  190. package/build-module/post-comments-form/form.js +46 -5
  191. package/build-module/post-comments-form/form.js.map +1 -1
  192. package/build-module/post-terms/edit.js +3 -2
  193. package/build-module/post-terms/edit.js.map +1 -1
  194. package/build-module/query-no-results/edit.js +2 -2
  195. package/build-module/query-no-results/edit.js.map +1 -1
  196. package/build-module/query-pagination-next/edit.js +2 -1
  197. package/build-module/query-pagination-next/edit.js.map +1 -1
  198. package/build-module/query-pagination-previous/edit.js +2 -1
  199. package/build-module/query-pagination-previous/edit.js.map +1 -1
  200. package/build-module/quote/deprecated.js +162 -36
  201. package/build-module/quote/deprecated.js.map +1 -1
  202. package/build-module/quote/edit.js +77 -43
  203. package/build-module/quote/edit.js.map +1 -1
  204. package/build-module/quote/index.js +9 -39
  205. package/build-module/quote/index.js.map +1 -1
  206. package/build-module/quote/save.js +4 -8
  207. package/build-module/quote/save.js.map +1 -1
  208. package/build-module/quote/transforms.js +111 -158
  209. package/build-module/quote/transforms.js.map +1 -1
  210. package/build-module/social-link/icons/index.js +1 -0
  211. package/build-module/social-link/icons/index.js.map +1 -1
  212. package/build-module/social-link/icons/whatsapp.js +15 -0
  213. package/build-module/social-link/icons/whatsapp.js.map +1 -0
  214. package/build-module/social-link/variations.js +8 -1
  215. package/build-module/social-link/variations.js.map +1 -1
  216. package/build-module/template-part/edit/index.js +20 -11
  217. package/build-module/template-part/edit/index.js.map +1 -1
  218. package/build-module/template-part/edit/selection-modal.js +33 -15
  219. package/build-module/template-part/edit/selection-modal.js.map +1 -1
  220. package/build-module/template-part/edit/utils/search.js +84 -0
  221. package/build-module/template-part/edit/utils/search.js.map +1 -0
  222. package/build-style/button/style-rtl.css +1 -1
  223. package/build-style/button/style.css +1 -1
  224. package/build-style/comments/editor-rtl.css +122 -0
  225. package/build-style/comments/editor.css +122 -0
  226. package/build-style/{post-comments → comments}/style-rtl.css +1 -0
  227. package/build-style/{post-comments → comments}/style.css +1 -0
  228. package/build-style/common-rtl.css +7 -0
  229. package/build-style/common.css +7 -0
  230. package/build-style/cover/style-rtl.css +2 -2
  231. package/build-style/cover/style.css +2 -2
  232. package/build-style/{post-comments/editor.css → editor-elements-rtl.css} +8 -2
  233. package/build-style/{post-comments/editor-rtl.css → editor-elements.css} +8 -2
  234. package/build-style/editor-rtl.css +151 -10
  235. package/build-style/editor.css +151 -10
  236. package/build-style/gallery/style-rtl.css +7 -2
  237. package/build-style/gallery/style.css +7 -2
  238. package/build-style/image/editor-rtl.css +4 -3
  239. package/build-style/image/editor.css +4 -3
  240. package/build-style/image/style-rtl.css +33 -3
  241. package/build-style/image/style.css +33 -3
  242. package/build-style/post-comments-form/style-rtl.css +0 -1
  243. package/build-style/post-comments-form/style.css +0 -1
  244. package/build-style/social-link/editor-rtl.css +1 -0
  245. package/build-style/social-link/editor.css +1 -0
  246. package/build-style/social-links/style-rtl.css +8 -0
  247. package/build-style/social-links/style.css +8 -0
  248. package/build-style/style-rtl.css +170 -127
  249. package/build-style/style.css +170 -127
  250. package/build-style/template-part/editor-rtl.css +14 -3
  251. package/build-style/template-part/editor.css +14 -3
  252. package/package.json +28 -28
  253. package/src/button/edit.js +1 -0
  254. package/src/button/style.scss +3 -1
  255. package/src/buttons/edit.js +1 -5
  256. package/src/columns/edit.native.js +2 -2
  257. package/src/comments/block.json +6 -1
  258. package/src/comments/edit/comments-legacy.js +71 -0
  259. package/src/comments/edit/index.js +35 -0
  260. package/src/comments/edit/placeholder.js +124 -0
  261. package/src/comments/{edit.js → edit/template.js} +1 -28
  262. package/src/comments/editor.scss +9 -0
  263. package/src/comments/index.php +219 -0
  264. package/src/comments/save.js +8 -7
  265. package/src/{post-comments → comments}/style.scss +7 -0
  266. package/src/common.scss +2 -0
  267. package/src/cover/style.scss +2 -2
  268. package/src/cover/transforms.js +2 -2
  269. package/src/editor-elements.scss +10 -0
  270. package/src/editor.scss +2 -1
  271. package/src/embed/embed-placeholder.native.js +2 -3
  272. package/src/gallery/edit.js +4 -2
  273. package/src/gallery/style.scss +10 -1
  274. package/src/gallery/use-get-media.native.js +44 -0
  275. package/src/group/block.json +1 -0
  276. package/src/group/variations.js +2 -2
  277. package/src/image/block.json +7 -1
  278. package/src/image/deprecated.js +86 -0
  279. package/src/image/edit.js +6 -1
  280. package/src/image/edit.native.js +18 -7
  281. package/src/image/editor.scss +9 -4
  282. package/src/image/image.js +26 -16
  283. package/src/image/save.js +10 -1
  284. package/src/image/style.scss +39 -3
  285. package/src/index.js +0 -2
  286. package/src/index.native.js +2 -11
  287. package/src/list/transforms.js +0 -47
  288. package/src/list/v2/transforms.js +2 -40
  289. package/src/list-item/edit.js +10 -12
  290. package/src/list-item/hooks/index.js +1 -1
  291. package/src/list-item/hooks/use-merge.js +141 -0
  292. package/src/list-item/hooks/use-outdent-list-item.js +72 -74
  293. package/src/list-item/utils.js +27 -3
  294. package/src/media-text/deprecated.js +148 -1
  295. package/src/media-text/edit.js +2 -1
  296. package/src/media-text/save.js +18 -0
  297. package/src/more/save.js +3 -6
  298. package/src/navigation-link/edit.js +4 -3
  299. package/src/navigation-submenu/edit.js +1 -0
  300. package/src/page-list/edit.js +9 -0
  301. package/src/paragraph/edit.js +8 -14
  302. package/src/post-comments-form/edit.js +2 -71
  303. package/src/post-comments-form/form.js +80 -5
  304. package/src/post-comments-form/index.php +1 -1
  305. package/src/post-comments-form/style.scss +0 -1
  306. package/src/post-terms/edit.js +3 -2
  307. package/src/query-no-results/edit.js +2 -5
  308. package/src/query-pagination-next/edit.js +1 -0
  309. package/src/query-pagination-previous/edit.js +1 -0
  310. package/src/quote/deprecated.js +213 -99
  311. package/src/quote/edit.js +77 -52
  312. package/src/quote/index.js +10 -33
  313. package/src/quote/save.js +5 -5
  314. package/src/quote/{v2/test → test}/migrate.js +2 -7
  315. package/src/quote/transforms.js +117 -147
  316. package/src/social-link/editor.scss +3 -0
  317. package/src/social-link/icons/index.js +1 -0
  318. package/src/social-link/icons/whatsapp.js +10 -0
  319. package/src/social-link/index.php +4 -0
  320. package/src/social-link/socials-with-bg.scss +5 -0
  321. package/src/social-link/socials-without-bg.scss +5 -0
  322. package/src/social-link/variations.js +7 -0
  323. package/src/style.scss +1 -2
  324. package/src/template-part/edit/index.js +37 -24
  325. package/src/template-part/edit/selection-modal.js +68 -40
  326. package/src/template-part/edit/utils/search.js +76 -0
  327. package/src/template-part/editor.scss +21 -9
  328. package/src/template-part/index.php +56 -2
  329. package/build/comments/edit.js.map +0 -1
  330. package/build/list-item/hooks/use-backspace.js +0 -59
  331. package/build/list-item/hooks/use-backspace.js.map +0 -1
  332. package/build/post-comments/edit.js +0 -184
  333. package/build/post-comments/edit.js.map +0 -1
  334. package/build/post-comments/index.js +0 -72
  335. package/build/post-comments/index.js.map +0 -1
  336. package/build/quote/v2/deprecated.js +0 -133
  337. package/build/quote/v2/deprecated.js.map +0 -1
  338. package/build/quote/v2/edit.js +0 -139
  339. package/build/quote/v2/edit.js.map +0 -1
  340. package/build/quote/v2/index.js +0 -49
  341. package/build/quote/v2/index.js.map +0 -1
  342. package/build/quote/v2/save.js +0 -43
  343. package/build/quote/v2/save.js.map +0 -1
  344. package/build/quote/v2/transforms.js +0 -156
  345. package/build/quote/v2/transforms.js.map +0 -1
  346. package/build-module/comments/edit.js +0 -59
  347. package/build-module/comments/edit.js.map +0 -1
  348. package/build-module/list-item/hooks/use-backspace.js +0 -44
  349. package/build-module/list-item/hooks/use-backspace.js.map +0 -1
  350. package/build-module/post-comments/edit.js +0 -171
  351. package/build-module/post-comments/edit.js.map +0 -1
  352. package/build-module/post-comments/index.js +0 -59
  353. package/build-module/post-comments/index.js.map +0 -1
  354. package/build-module/quote/v2/deprecated.js +0 -116
  355. package/build-module/quote/v2/deprecated.js.map +0 -1
  356. package/build-module/quote/v2/edit.js +0 -122
  357. package/build-module/quote/v2/edit.js.map +0 -1
  358. package/build-module/quote/v2/index.js +0 -33
  359. package/build-module/quote/v2/index.js.map +0 -1
  360. package/build-module/quote/v2/save.js +0 -30
  361. package/build-module/quote/v2/save.js.map +0 -1
  362. package/build-module/quote/v2/transforms.js +0 -147
  363. package/build-module/quote/v2/transforms.js.map +0 -1
  364. package/src/list-item/hooks/use-backspace.js +0 -51
  365. package/src/post-comments/block.json +0 -45
  366. package/src/post-comments/edit.js +0 -247
  367. package/src/post-comments/editor.scss +0 -3
  368. package/src/post-comments/index.js +0 -18
  369. package/src/post-comments/index.php +0 -87
  370. package/src/quote/v2/deprecated.js +0 -107
  371. package/src/quote/v2/edit.js +0 -139
  372. package/src/quote/v2/index.js +0 -36
  373. package/src/quote/v2/save.js +0 -26
  374. package/src/quote/v2/transforms.js +0 -155
@@ -22,12 +22,13 @@ import { useMergeRefs } from '@wordpress/compose';
22
22
  */
23
23
  import {
24
24
  useEnter,
25
- useBackspace,
26
25
  useSpace,
27
26
  useIndentListItem,
28
27
  useOutdentListItem,
29
28
  useSplit,
29
+ useMerge,
30
30
  } from './hooks';
31
+ import { convertToListItems } from './utils';
31
32
 
32
33
  function IndentUI( { clientId } ) {
33
34
  const [ canIndent, indentListItem ] = useIndentListItem( clientId );
@@ -40,14 +41,14 @@ function IndentUI( { clientId } ) {
40
41
  title={ __( 'Outdent' ) }
41
42
  describedBy={ __( 'Outdent list item' ) }
42
43
  disabled={ ! canOutdent }
43
- onClick={ outdentListItem }
44
+ onClick={ () => outdentListItem() }
44
45
  />
45
46
  <ToolbarButton
46
47
  icon={ isRTL() ? formatIndentRTL : formatIndent }
47
48
  title={ __( 'Indent' ) }
48
49
  describedBy={ __( 'Indent list item' ) }
49
50
  isDisabled={ ! canIndent }
50
- onClick={ indentListItem }
51
+ onClick={ () => indentListItem() }
51
52
  />
52
53
  </>
53
54
  );
@@ -56,7 +57,6 @@ function IndentUI( { clientId } ) {
56
57
  export default function ListItemEdit( {
57
58
  attributes,
58
59
  setAttributes,
59
- mergeBlocks,
60
60
  onReplace,
61
61
  clientId,
62
62
  } ) {
@@ -66,18 +66,14 @@ export default function ListItemEdit( {
66
66
  allowedBlocks: [ 'core/list' ],
67
67
  } );
68
68
  const useEnterRef = useEnter( { content, clientId } );
69
- const useBackspaceRef = useBackspace( { clientId } );
70
69
  const useSpaceRef = useSpace( clientId );
71
70
  const onSplit = useSplit( clientId );
71
+ const onMerge = useMerge( clientId );
72
72
  return (
73
73
  <>
74
74
  <li { ...innerBlocksProps }>
75
75
  <RichText
76
- ref={ useMergeRefs( [
77
- useEnterRef,
78
- useBackspaceRef,
79
- useSpaceRef,
80
- ] ) }
76
+ ref={ useMergeRefs( [ useEnterRef, useSpaceRef ] ) }
81
77
  identifier="content"
82
78
  tagName="div"
83
79
  onChange={ ( nextContent ) =>
@@ -87,8 +83,10 @@ export default function ListItemEdit( {
87
83
  aria-label={ __( 'List text' ) }
88
84
  placeholder={ placeholder || __( 'List' ) }
89
85
  onSplit={ onSplit }
90
- onMerge={ mergeBlocks }
91
- onReplace={ onReplace }
86
+ onMerge={ onMerge }
87
+ onReplace={ ( blocks, ...args ) => {
88
+ onReplace( convertToListItems( blocks ), ...args );
89
+ } }
92
90
  />
93
91
  { innerBlocksProps.children }
94
92
  </li>
@@ -1,6 +1,6 @@
1
1
  export { default as useOutdentListItem } from './use-outdent-list-item';
2
2
  export { default as useIndentListItem } from './use-indent-list-item';
3
3
  export { default as useEnter } from './use-enter';
4
- export { default as useBackspace } from './use-backspace';
5
4
  export { default as useSpace } from './use-space';
6
5
  export { default as useSplit } from './use-split';
6
+ export { default as useMerge } from './use-merge';
@@ -0,0 +1,141 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useRegistry, useDispatch, useSelect } from '@wordpress/data';
5
+ import { store as blockEditorStore } from '@wordpress/block-editor';
6
+ import { getDefaultBlockName, switchToBlockType } from '@wordpress/blocks';
7
+
8
+ /**
9
+ * Internal dependencies
10
+ */
11
+ import useOutdentListItem from './use-outdent-list-item';
12
+
13
+ import { name as listItemName } from '../block.json';
14
+
15
+ export default function useMerge( clientId ) {
16
+ const registry = useRegistry();
17
+ const {
18
+ getPreviousBlockClientId,
19
+ getNextBlockClientId,
20
+ getBlockOrder,
21
+ getBlockRootClientId,
22
+ getBlockName,
23
+ getBlock,
24
+ } = useSelect( blockEditorStore );
25
+ const { mergeBlocks, moveBlocksToPosition, replaceBlock, selectBlock } =
26
+ useDispatch( blockEditorStore );
27
+ const [ , outdentListItem ] = useOutdentListItem( clientId );
28
+
29
+ function getTrailingId( id ) {
30
+ const order = getBlockOrder( id );
31
+
32
+ if ( ! order.length ) {
33
+ return id;
34
+ }
35
+
36
+ return getTrailingId( order[ order.length - 1 ] );
37
+ }
38
+
39
+ function getParentListItemId( id ) {
40
+ const listId = getBlockRootClientId( id );
41
+ const parentListItemId = getBlockRootClientId( listId );
42
+ if ( ! parentListItemId ) return;
43
+ if ( getBlockName( parentListItemId ) !== listItemName ) return;
44
+ return parentListItemId;
45
+ }
46
+
47
+ /**
48
+ * Return the next list item with respect to the given list item. If none,
49
+ * return the next list item of the parent list item if it exists.
50
+ *
51
+ * @param {string} id A list item client ID.
52
+ * @return {string?} The client ID of the next list item.
53
+ */
54
+ function _getNextId( id ) {
55
+ const next = getNextBlockClientId( id );
56
+ if ( next ) return next;
57
+ const parentListItemId = getParentListItemId( id );
58
+ if ( ! parentListItemId ) return;
59
+ return _getNextId( parentListItemId );
60
+ }
61
+
62
+ /**
63
+ * Given a client ID, return the client ID of the list item on the next
64
+ * line, regardless of indentation level.
65
+ *
66
+ * @param {string} id The client ID of the current list item.
67
+ * @return {string?} The client ID of the next list item.
68
+ */
69
+ function getNextId( id ) {
70
+ const order = getBlockOrder( id );
71
+
72
+ // If the list item does not have a nested list, return the next list
73
+ // item.
74
+ if ( ! order.length ) {
75
+ return _getNextId( id );
76
+ }
77
+
78
+ // Get the first list item in the nested list.
79
+ return getBlockOrder( order[ 0 ] )[ 0 ];
80
+ }
81
+
82
+ function switchToDefaultBlockType( forward ) {
83
+ const rootClientId = getBlockRootClientId( clientId );
84
+ const replacement = switchToBlockType(
85
+ getBlock( rootClientId ),
86
+ getDefaultBlockName()
87
+ );
88
+ const indexToSelect = forward ? replacement.length - 1 : 0;
89
+ const initialPosition = forward ? -1 : 0;
90
+ registry.batch( () => {
91
+ replaceBlock( rootClientId, replacement );
92
+ selectBlock(
93
+ replacement[ indexToSelect ].clientId,
94
+ initialPosition
95
+ );
96
+ } );
97
+ }
98
+
99
+ return ( forward ) => {
100
+ if ( forward ) {
101
+ const nextBlockClientId = getNextId( clientId );
102
+
103
+ if ( ! nextBlockClientId ) {
104
+ switchToDefaultBlockType( forward );
105
+ return;
106
+ }
107
+
108
+ if ( getParentListItemId( nextBlockClientId ) ) {
109
+ outdentListItem( nextBlockClientId );
110
+ } else {
111
+ registry.batch( () => {
112
+ moveBlocksToPosition(
113
+ getBlockOrder( nextBlockClientId ),
114
+ nextBlockClientId,
115
+ getPreviousBlockClientId( nextBlockClientId )
116
+ );
117
+ mergeBlocks( clientId, nextBlockClientId );
118
+ } );
119
+ }
120
+ } else {
121
+ // Merging is only done from the top level. For lowel levels, the
122
+ // list item is outdented instead.
123
+ const previousBlockClientId = getPreviousBlockClientId( clientId );
124
+ if ( getParentListItemId( clientId ) ) {
125
+ outdentListItem( clientId );
126
+ } else if ( previousBlockClientId ) {
127
+ const trailingId = getTrailingId( previousBlockClientId );
128
+ registry.batch( () => {
129
+ moveBlocksToPosition(
130
+ getBlockOrder( clientId ),
131
+ clientId,
132
+ previousBlockClientId
133
+ );
134
+ mergeBlocks( trailingId, clientId );
135
+ } );
136
+ } else {
137
+ switchToDefaultBlockType( forward );
138
+ }
139
+ }
140
+ };
141
+ }
@@ -1,22 +1,23 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { first, last } from 'lodash';
4
+ import { first, last, castArray } from 'lodash';
5
5
 
6
6
  /**
7
7
  * WordPress dependencies
8
8
  */
9
9
  import { useCallback } from '@wordpress/element';
10
- import { useSelect, useDispatch } from '@wordpress/data';
10
+ import { useSelect, useDispatch, useRegistry } from '@wordpress/data';
11
11
  import { store as blockEditorStore } from '@wordpress/block-editor';
12
12
  import { cloneBlock } from '@wordpress/blocks';
13
13
 
14
14
  /**
15
15
  * Internal dependencies
16
16
  */
17
- import { createListItem } from '../utils';
17
+ import { name as listItemName } from '../block.json';
18
18
 
19
19
  export default function useOutdentListItem( clientId ) {
20
+ const registry = useRegistry();
20
21
  const { canOutdent } = useSelect(
21
22
  ( innerSelect ) => {
22
23
  const { getBlockRootClientId } = innerSelect( blockEditorStore );
@@ -29,93 +30,90 @@ export default function useOutdentListItem( clientId ) {
29
30
  },
30
31
  [ clientId ]
31
32
  );
32
- const { replaceBlocks, selectionChange, multiSelect } =
33
- useDispatch( blockEditorStore );
33
+ const {
34
+ moveBlocksToPosition,
35
+ removeBlock,
36
+ insertBlock,
37
+ updateBlockListSettings,
38
+ } = useDispatch( blockEditorStore );
34
39
  const {
35
40
  getBlockRootClientId,
36
- getBlockAttributes,
37
- getBlock,
41
+ getBlockName,
42
+ getBlockOrder,
38
43
  getBlockIndex,
39
- getSelectionStart,
40
- getSelectionEnd,
41
- hasMultiSelection,
42
- getMultiSelectedBlockClientIds,
44
+ getSelectedBlockClientIds,
45
+ getBlock,
46
+ getBlockListSettings,
43
47
  } = useSelect( blockEditorStore );
44
48
 
49
+ function getParentListItemId( id ) {
50
+ const listId = getBlockRootClientId( id );
51
+ const parentListItemId = getBlockRootClientId( listId );
52
+ if ( ! parentListItemId ) return;
53
+ if ( getBlockName( parentListItemId ) !== listItemName ) return;
54
+ return parentListItemId;
55
+ }
56
+
45
57
  return [
46
58
  canOutdent,
47
- useCallback( () => {
48
- const _hasMultiSelection = hasMultiSelection();
49
- const clientIds = _hasMultiSelection
50
- ? getMultiSelectedBlockClientIds()
51
- : [ clientId ];
59
+ useCallback( ( clientIds = getSelectedBlockClientIds() ) => {
60
+ clientIds = castArray( clientIds );
52
61
 
53
- const selectionStart = getSelectionStart();
54
- const selectionEnd = getSelectionEnd();
62
+ if ( ! clientIds.length ) return;
55
63
 
56
- const listParentId = getBlockRootClientId( clientId );
57
- const listAttributes = getBlockAttributes( listParentId );
58
- const listItemParentId = getBlockRootClientId( listParentId );
59
- const listItemParentAttributes =
60
- getBlockAttributes( listItemParentId );
64
+ const firstClientId = first( clientIds );
61
65
 
62
- const firstIndex = getBlockIndex( first( clientIds ) );
63
- const lastIndex = getBlockIndex( last( clientIds ) );
64
- const siblingBlocks = getBlock( listParentId ).innerBlocks;
65
- const previousSiblings = siblingBlocks.slice( 0, firstIndex );
66
- const afterSiblings = siblingBlocks.slice( lastIndex + 1 );
66
+ // Can't outdent if it's not a list item.
67
+ if ( getBlockName( firstClientId ) !== listItemName ) return;
67
68
 
68
- // Create a new parent list item block with just the siblings
69
- // that existed before the first child item being outdent.
70
- const newListItemParent = createListItem(
71
- listItemParentAttributes,
72
- listAttributes,
73
- previousSiblings
74
- );
69
+ const parentListItemId = getParentListItemId( firstClientId );
75
70
 
76
- const lastBlock = getBlock( last( clientIds ) );
77
- const childList = lastBlock.innerBlocks[ 0 ];
78
- const childItems = childList?.innerBlocks || [];
79
- const hasChildItems = !! childItems.length;
71
+ // Can't outdent if it's at the top level.
72
+ if ( ! parentListItemId ) return;
80
73
 
81
- const newBlocksExcludingLast = clientIds
82
- .slice( 0, -1 )
83
- .map( ( _clientId ) => cloneBlock( getBlock( _clientId ) ) );
84
-
85
- // Create a new list item block whose attributes are equal to the
86
- // last block being outdent and whose children are the children that it had (if any)
87
- // followed by the siblings that existed after it.
88
- const newLastItem = createListItem(
89
- lastBlock.attributes,
90
- hasChildItems ? childList.attributes : listAttributes,
91
- [ ...childItems, ...afterSiblings ]
74
+ const parentListId = getBlockRootClientId( firstClientId );
75
+ const lastClientId = last( clientIds );
76
+ const order = getBlockOrder( parentListId );
77
+ const followingListItems = order.slice(
78
+ getBlockIndex( lastClientId ) + 1
92
79
  );
93
80
 
94
- // Replace the parent list item block, with a new block containing
95
- // the previous siblings before the first block being outdent,
96
- // followed by the blocks being outdent with the after siblings added
97
- // as children of the last block.
98
- replaceBlocks(
99
- [ listItemParentId ],
100
- [ newListItemParent, ...newBlocksExcludingLast, newLastItem ]
101
- );
81
+ registry.batch( () => {
82
+ if ( followingListItems.length ) {
83
+ let nestedListId = first( getBlockOrder( firstClientId ) );
102
84
 
103
- // Restore the selection state.
104
- if ( ! _hasMultiSelection ) {
105
- selectionChange(
106
- newLastItem.clientId,
107
- selectionEnd.attributeKey,
108
- selectionEnd.clientId === selectionStart.clientId
109
- ? selectionStart.offset
110
- : selectionEnd.offset,
111
- selectionEnd.offset
112
- );
113
- } else {
114
- multiSelect(
115
- first( newBlocksExcludingLast ).clientId,
116
- newLastItem.clientId
85
+ if ( ! nestedListId ) {
86
+ const nestedListBlock = cloneBlock(
87
+ getBlock( parentListId ),
88
+ {},
89
+ []
90
+ );
91
+ nestedListId = nestedListBlock.clientId;
92
+ insertBlock( nestedListBlock, 0, firstClientId, false );
93
+ // Immediately update the block list settings, otherwise
94
+ // blocks can't be moved here due to canInsert checks.
95
+ updateBlockListSettings(
96
+ nestedListId,
97
+ getBlockListSettings( parentListId )
98
+ );
99
+ }
100
+
101
+ moveBlocksToPosition(
102
+ followingListItems,
103
+ parentListId,
104
+ nestedListId
105
+ );
106
+ }
107
+ moveBlocksToPosition(
108
+ clientIds,
109
+ parentListId,
110
+ getBlockRootClientId( parentListItemId ),
111
+ getBlockIndex( parentListItemId ) + 1
117
112
  );
118
- }
119
- }, [ clientId ] ),
113
+ if ( ! getBlockOrder( parentListId ).length ) {
114
+ removeBlock( parentListId );
115
+ }
116
+ } );
117
+ }, [] ),
120
118
  ];
121
119
  }
@@ -1,14 +1,38 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { createBlock } from '@wordpress/blocks';
4
+ import { createBlock, switchToBlockType } from '@wordpress/blocks';
5
+
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+ import { name as listItemName } from './block.json';
10
+ import { name as listName } from '../list/block.json';
5
11
 
6
12
  export function createListItem( listItemAttributes, listAttributes, children ) {
7
13
  return createBlock(
8
- 'core/list-item',
14
+ listItemName,
9
15
  listItemAttributes,
10
16
  ! children?.length
11
17
  ? []
12
- : [ createBlock( 'core/list', listAttributes, children ) ]
18
+ : [ createBlock( listName, listAttributes, children ) ]
13
19
  );
14
20
  }
21
+
22
+ export function convertToListItems( blocks ) {
23
+ const listItems = [];
24
+
25
+ for ( let block of blocks ) {
26
+ if ( block.name === listItemName ) {
27
+ listItems.push( block );
28
+ } else if ( block.name === listName ) {
29
+ listItems.push( ...block.innerBlocks );
30
+ } else if ( ( block = switchToBlockType( block, listName ) ) ) {
31
+ for ( const { innerBlocks } of block ) {
32
+ listItems.push( ...innerBlocks );
33
+ }
34
+ }
35
+ }
36
+
37
+ return listItems;
38
+ }
@@ -7,12 +7,18 @@ import { isEmpty, omit } from 'lodash';
7
7
  /**
8
8
  * WordPress dependencies
9
9
  */
10
- import { InnerBlocks, getColorClassName } from '@wordpress/block-editor';
10
+ import {
11
+ InnerBlocks,
12
+ getColorClassName,
13
+ useInnerBlocksProps,
14
+ useBlockProps,
15
+ } from '@wordpress/block-editor';
11
16
 
12
17
  /**
13
18
  * Internal dependencies
14
19
  */
15
20
  import { imageFillStyles } from './media-container';
21
+ import { DEFAULT_MEDIA_SIZE_SLUG } from './constants';
16
22
 
17
23
  const DEFAULT_MEDIA_WIDTH = 50;
18
24
  const noop = () => {};
@@ -68,6 +74,147 @@ const baseAttributes = {
68
74
  };
69
75
 
70
76
  export default [
77
+ // Version with CSS grid
78
+ {
79
+ attributes: {
80
+ ...baseAttributes,
81
+ mediaUrl: {
82
+ type: 'string',
83
+ source: 'attribute',
84
+ selector: 'figure video,figure img',
85
+ attribute: 'src',
86
+ },
87
+ mediaLink: {
88
+ type: 'string',
89
+ },
90
+ linkDestination: {
91
+ type: 'string',
92
+ },
93
+ linkTarget: {
94
+ type: 'string',
95
+ source: 'attribute',
96
+ selector: 'figure a',
97
+ attribute: 'target',
98
+ },
99
+ href: {
100
+ type: 'string',
101
+ source: 'attribute',
102
+ selector: 'figure a',
103
+ attribute: 'href',
104
+ },
105
+ rel: {
106
+ type: 'string',
107
+ source: 'attribute',
108
+ selector: 'figure a',
109
+ attribute: 'rel',
110
+ },
111
+ linkClass: {
112
+ type: 'string',
113
+ source: 'attribute',
114
+ selector: 'figure a',
115
+ attribute: 'class',
116
+ },
117
+ verticalAlignment: {
118
+ type: 'string',
119
+ },
120
+ imageFill: {
121
+ type: 'boolean',
122
+ },
123
+ focalPoint: {
124
+ type: 'object',
125
+ },
126
+ },
127
+ save( { attributes } ) {
128
+ const {
129
+ isStackedOnMobile,
130
+ mediaAlt,
131
+ mediaPosition,
132
+ mediaType,
133
+ mediaUrl,
134
+ mediaWidth,
135
+ mediaId,
136
+ verticalAlignment,
137
+ imageFill,
138
+ focalPoint,
139
+ linkClass,
140
+ href,
141
+ linkTarget,
142
+ rel,
143
+ } = attributes;
144
+ const mediaSizeSlug =
145
+ attributes.mediaSizeSlug || DEFAULT_MEDIA_SIZE_SLUG;
146
+ const newRel = isEmpty( rel ) ? undefined : rel;
147
+
148
+ const imageClasses = classnames( {
149
+ [ `wp-image-${ mediaId }` ]: mediaId && mediaType === 'image',
150
+ [ `size-${ mediaSizeSlug }` ]: mediaId && mediaType === 'image',
151
+ } );
152
+
153
+ let image = (
154
+ <img
155
+ src={ mediaUrl }
156
+ alt={ mediaAlt }
157
+ className={ imageClasses || null }
158
+ />
159
+ );
160
+
161
+ if ( href ) {
162
+ image = (
163
+ <a
164
+ className={ linkClass }
165
+ href={ href }
166
+ target={ linkTarget }
167
+ rel={ newRel }
168
+ >
169
+ { image }
170
+ </a>
171
+ );
172
+ }
173
+
174
+ const mediaTypeRenders = {
175
+ image: () => image,
176
+ video: () => <video controls src={ mediaUrl } />,
177
+ };
178
+
179
+ const className = classnames( {
180
+ 'has-media-on-the-right': 'right' === mediaPosition,
181
+ 'is-stacked-on-mobile': isStackedOnMobile,
182
+ [ `is-vertically-aligned-${ verticalAlignment }` ]:
183
+ verticalAlignment,
184
+ 'is-image-fill': imageFill,
185
+ } );
186
+ const backgroundStyles = imageFill
187
+ ? imageFillStyles( mediaUrl, focalPoint )
188
+ : {};
189
+
190
+ let gridTemplateColumns;
191
+ if ( mediaWidth !== DEFAULT_MEDIA_WIDTH ) {
192
+ gridTemplateColumns =
193
+ 'right' === mediaPosition
194
+ ? `auto ${ mediaWidth }%`
195
+ : `${ mediaWidth }% auto`;
196
+ }
197
+ const style = {
198
+ gridTemplateColumns,
199
+ };
200
+
201
+ return (
202
+ <div { ...useBlockProps.save( { className, style } ) }>
203
+ <figure
204
+ className="wp-block-media-text__media"
205
+ style={ backgroundStyles }
206
+ >
207
+ { ( mediaTypeRenders[ mediaType ] || noop )() }
208
+ </figure>
209
+ <div
210
+ { ...useInnerBlocksProps.save( {
211
+ className: 'wp-block-media-text__content',
212
+ } ) }
213
+ />
214
+ </div>
215
+ );
216
+ },
217
+ },
71
218
  {
72
219
  attributes: {
73
220
  ...baseAttributes,
@@ -354,6 +354,7 @@ function MediaTextEdit( { attributes, isSelected, setAttributes } ) {
354
354
  ) }
355
355
  </BlockControls>
356
356
  <div { ...blockProps }>
357
+ { mediaPosition === 'right' && <div { ...innerBlocksProps } /> }
357
358
  <MediaContainer
358
359
  className="wp-block-media-text__media"
359
360
  onSelectMedia={ onSelectMedia }
@@ -373,7 +374,7 @@ function MediaTextEdit( { attributes, isSelected, setAttributes } ) {
373
374
  mediaWidth,
374
375
  } }
375
376
  />
376
- <div { ...innerBlocksProps } />
377
+ { mediaPosition !== 'right' && <div { ...innerBlocksProps } /> }
377
378
  </div>
378
379
  </>
379
380
  );
@@ -88,6 +88,24 @@ export default function save( { attributes } ) {
88
88
  const style = {
89
89
  gridTemplateColumns,
90
90
  };
91
+
92
+ if ( 'right' === mediaPosition ) {
93
+ return (
94
+ <div { ...useBlockProps.save( { className, style } ) }>
95
+ <div
96
+ { ...useInnerBlocksProps.save( {
97
+ className: 'wp-block-media-text__content',
98
+ } ) }
99
+ />
100
+ <figure
101
+ className="wp-block-media-text__media"
102
+ style={ backgroundStyles }
103
+ >
104
+ { ( mediaTypeRenders[ mediaType ] || noop )() }
105
+ </figure>
106
+ </div>
107
+ );
108
+ }
91
109
  return (
92
110
  <div { ...useBlockProps.save( { className, style } ) }>
93
111
  <figure
package/src/more/save.js CHANGED
@@ -1,8 +1,3 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { compact } from 'lodash';
5
-
6
1
  /**
7
2
  * WordPress dependencies
8
3
  */
@@ -14,6 +9,8 @@ export default function save( { attributes: { customText, noTeaser } } ) {
14
9
  const noTeaserTag = noTeaser ? '<!--noteaser-->' : '';
15
10
 
16
11
  return (
17
- <RawHTML>{ compact( [ moreTag, noTeaserTag ] ).join( '\n' ) }</RawHTML>
12
+ <RawHTML>
13
+ { [ moreTag, noTeaserTag ].filter( Boolean ).join( '\n' ) }
14
+ </RawHTML>
18
15
  );
19
16
  }