@wordpress/block-library 8.18.1-next.5a1d1283.0 → 8.19.1

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 (386) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +1 -1
  3. package/build/block/edit.js +53 -2
  4. package/build/block/edit.js.map +1 -1
  5. package/build/button/edit.js +7 -4
  6. package/build/button/edit.js.map +1 -1
  7. package/build/button/index.js +11 -2
  8. package/build/button/index.js.map +1 -1
  9. package/build/button/save.js +10 -4
  10. package/build/button/save.js.map +1 -1
  11. package/build/buttons/edit.js +12 -3
  12. package/build/buttons/edit.js.map +1 -1
  13. package/build/code/edit.js +8 -2
  14. package/build/code/edit.js.map +1 -1
  15. package/build/code/index.js +7 -1
  16. package/build/code/index.js.map +1 -1
  17. package/build/column/index.js +1 -0
  18. package/build/column/index.js.map +1 -1
  19. package/build/columns/index.js +2 -0
  20. package/build/columns/index.js.map +1 -1
  21. package/build/file/edit.native.js +1 -1
  22. package/build/file/edit.native.js.map +1 -1
  23. package/build/file/index.js +2 -1
  24. package/build/file/index.js.map +1 -1
  25. package/build/file/utils/index.js +1 -15
  26. package/build/file/utils/index.js.map +1 -1
  27. package/build/file/view.js +14 -1
  28. package/build/file/view.js.map +1 -1
  29. package/build/footnotes/edit.js +12 -2
  30. package/build/footnotes/edit.js.map +1 -1
  31. package/build/gallery/edit.js +1 -1
  32. package/build/gallery/edit.js.map +1 -1
  33. package/build/group/edit.js +0 -1
  34. package/build/group/edit.js.map +1 -1
  35. package/build/group/index.js +4 -0
  36. package/build/group/index.js.map +1 -1
  37. package/build/heading/edit.js +0 -1
  38. package/build/heading/edit.js.map +1 -1
  39. package/build/heading/index.js +2 -0
  40. package/build/heading/index.js.map +1 -1
  41. package/build/heading/transforms.js +3 -6
  42. package/build/heading/transforms.js.map +1 -1
  43. package/build/image/deprecated.js +191 -7
  44. package/build/image/deprecated.js.map +1 -1
  45. package/build/image/edit.js +27 -12
  46. package/build/image/edit.js.map +1 -1
  47. package/build/image/image.js +75 -40
  48. package/build/image/image.js.map +1 -1
  49. package/build/image/index.js +7 -4
  50. package/build/image/index.js.map +1 -1
  51. package/build/image/{view-interactivity.js → view.js} +1 -1
  52. package/build/image/view.js.map +1 -0
  53. package/build/list/deprecated.js +93 -1
  54. package/build/list/deprecated.js.map +1 -1
  55. package/build/list/edit.js +10 -10
  56. package/build/list/edit.js.map +1 -1
  57. package/build/list/ordered-list-settings.js +10 -10
  58. package/build/list/ordered-list-settings.js.map +1 -1
  59. package/build/list/save.js +4 -2
  60. package/build/list/save.js.map +1 -1
  61. package/build/list/utils.js +21 -2
  62. package/build/list/utils.js.map +1 -1
  63. package/build/navigation/constants.js +1 -1
  64. package/build/navigation/constants.js.map +1 -1
  65. package/build/navigation/index.js +4 -2
  66. package/build/navigation/index.js.map +1 -1
  67. package/build/navigation/view.js +168 -82
  68. package/build/navigation/view.js.map +1 -1
  69. package/build/navigation-link/edit.js +3 -9
  70. package/build/navigation-link/edit.js.map +1 -1
  71. package/build/navigation-link/transforms.js +24 -0
  72. package/build/navigation-link/transforms.js.map +1 -1
  73. package/build/page-list/edit.js +2 -1
  74. package/build/page-list/edit.js.map +1 -1
  75. package/build/pattern/edit.js +2 -0
  76. package/build/pattern/edit.js.map +1 -1
  77. package/build/post-comments-form/edit.js +10 -2
  78. package/build/post-comments-form/edit.js.map +1 -1
  79. package/build/post-comments-form/form.js +5 -3
  80. package/build/post-comments-form/form.js.map +1 -1
  81. package/build/post-content/edit.js +8 -7
  82. package/build/post-content/edit.js.map +1 -1
  83. package/build/post-content/index.js +3 -0
  84. package/build/post-content/index.js.map +1 -1
  85. package/build/post-featured-image/overlay.js +2 -1
  86. package/build/post-featured-image/overlay.js.map +1 -1
  87. package/build/preformatted/edit.js +4 -1
  88. package/build/preformatted/edit.js.map +1 -1
  89. package/build/preformatted/index.js +1 -1
  90. package/build/preformatted/index.js.map +1 -1
  91. package/build/pullquote/deprecated.js +6 -7
  92. package/build/pullquote/deprecated.js.map +1 -1
  93. package/build/query/edit/enhanced-pagination-modal.js +56 -0
  94. package/build/query/edit/enhanced-pagination-modal.js.map +1 -0
  95. package/build/query/edit/inspector-controls/enhanced-pagination-control.js +42 -0
  96. package/build/query/edit/inspector-controls/enhanced-pagination-control.js.map +1 -0
  97. package/build/query/edit/inspector-controls/index.js +8 -25
  98. package/build/query/edit/inspector-controls/index.js.map +1 -1
  99. package/build/query/edit/query-content.js +8 -2
  100. package/build/query/edit/query-content.js.map +1 -1
  101. package/build/query/utils.js +19 -0
  102. package/build/query/utils.js.map +1 -1
  103. package/build/query/view.js +21 -6
  104. package/build/query/view.js.map +1 -1
  105. package/build/search/index.js +1 -0
  106. package/build/search/index.js.map +1 -1
  107. package/build/search/view.js +81 -150
  108. package/build/search/view.js.map +1 -1
  109. package/build/social-link/edit.native.js +3 -1
  110. package/build/social-link/edit.native.js.map +1 -1
  111. package/build/table/edit.js +7 -7
  112. package/build/table/edit.js.map +1 -1
  113. package/build/table-of-contents/edit.js +2 -130
  114. package/build/table-of-contents/edit.js.map +1 -1
  115. package/build/table-of-contents/hooks.js +145 -0
  116. package/build/table-of-contents/hooks.js.map +1 -0
  117. package/build/table-of-contents/index.js +2 -1
  118. package/build/table-of-contents/index.js.map +1 -1
  119. package/build/verse/edit.js +4 -1
  120. package/build/verse/edit.js.map +1 -1
  121. package/build/verse/index.js +1 -1
  122. package/build/verse/index.js.map +1 -1
  123. package/build-module/block/edit.js +54 -3
  124. package/build-module/block/edit.js.map +1 -1
  125. package/build-module/button/edit.js +7 -4
  126. package/build-module/button/edit.js.map +1 -1
  127. package/build-module/button/index.js +11 -2
  128. package/build-module/button/index.js.map +1 -1
  129. package/build-module/button/save.js +10 -4
  130. package/build-module/button/save.js.map +1 -1
  131. package/build-module/buttons/edit.js +12 -3
  132. package/build-module/buttons/edit.js.map +1 -1
  133. package/build-module/code/edit.js +8 -2
  134. package/build-module/code/edit.js.map +1 -1
  135. package/build-module/code/index.js +7 -1
  136. package/build-module/code/index.js.map +1 -1
  137. package/build-module/column/index.js +1 -0
  138. package/build-module/column/index.js.map +1 -1
  139. package/build-module/columns/index.js +2 -0
  140. package/build-module/columns/index.js.map +1 -1
  141. package/build-module/file/edit.native.js +1 -1
  142. package/build-module/file/edit.native.js.map +1 -1
  143. package/build-module/file/index.js +2 -1
  144. package/build-module/file/index.js.map +1 -1
  145. package/build-module/file/utils/index.js +0 -13
  146. package/build-module/file/utils/index.js.map +1 -1
  147. package/build-module/file/view.js +14 -2
  148. package/build-module/file/view.js.map +1 -1
  149. package/build-module/footnotes/edit.js +12 -2
  150. package/build-module/footnotes/edit.js.map +1 -1
  151. package/build-module/gallery/edit.js +1 -1
  152. package/build-module/gallery/edit.js.map +1 -1
  153. package/build-module/group/edit.js +0 -1
  154. package/build-module/group/edit.js.map +1 -1
  155. package/build-module/group/index.js +4 -0
  156. package/build-module/group/index.js.map +1 -1
  157. package/build-module/heading/edit.js +0 -1
  158. package/build-module/heading/edit.js.map +1 -1
  159. package/build-module/heading/index.js +2 -0
  160. package/build-module/heading/index.js.map +1 -1
  161. package/build-module/heading/transforms.js +3 -6
  162. package/build-module/heading/transforms.js.map +1 -1
  163. package/build-module/image/deprecated.js +191 -7
  164. package/build-module/image/deprecated.js.map +1 -1
  165. package/build-module/image/edit.js +27 -12
  166. package/build-module/image/edit.js.map +1 -1
  167. package/build-module/image/image.js +77 -42
  168. package/build-module/image/image.js.map +1 -1
  169. package/build-module/image/index.js +7 -4
  170. package/build-module/image/index.js.map +1 -1
  171. package/build-module/image/{view-interactivity.js → view.js} +1 -1
  172. package/build-module/image/view.js.map +1 -0
  173. package/build-module/list/deprecated.js +95 -3
  174. package/build-module/list/deprecated.js.map +1 -1
  175. package/build-module/list/edit.js +10 -10
  176. package/build-module/list/edit.js.map +1 -1
  177. package/build-module/list/ordered-list-settings.js +10 -10
  178. package/build-module/list/ordered-list-settings.js.map +1 -1
  179. package/build-module/list/save.js +4 -2
  180. package/build-module/list/save.js.map +1 -1
  181. package/build-module/list/utils.js +20 -2
  182. package/build-module/list/utils.js.map +1 -1
  183. package/build-module/navigation/constants.js +1 -1
  184. package/build-module/navigation/constants.js.map +1 -1
  185. package/build-module/navigation/index.js +4 -2
  186. package/build-module/navigation/index.js.map +1 -1
  187. package/build-module/navigation/view.js +168 -83
  188. package/build-module/navigation/view.js.map +1 -1
  189. package/build-module/navigation-link/edit.js +3 -9
  190. package/build-module/navigation-link/edit.js.map +1 -1
  191. package/build-module/navigation-link/transforms.js +24 -0
  192. package/build-module/navigation-link/transforms.js.map +1 -1
  193. package/build-module/page-list/edit.js +2 -1
  194. package/build-module/page-list/edit.js.map +1 -1
  195. package/build-module/pattern/edit.js +2 -0
  196. package/build-module/pattern/edit.js.map +1 -1
  197. package/build-module/post-comments-form/edit.js +10 -2
  198. package/build-module/post-comments-form/edit.js.map +1 -1
  199. package/build-module/post-comments-form/form.js +5 -3
  200. package/build-module/post-comments-form/form.js.map +1 -1
  201. package/build-module/post-content/edit.js +8 -7
  202. package/build-module/post-content/edit.js.map +1 -1
  203. package/build-module/post-content/index.js +3 -0
  204. package/build-module/post-content/index.js.map +1 -1
  205. package/build-module/post-featured-image/overlay.js +2 -1
  206. package/build-module/post-featured-image/overlay.js.map +1 -1
  207. package/build-module/preformatted/edit.js +4 -1
  208. package/build-module/preformatted/edit.js.map +1 -1
  209. package/build-module/preformatted/index.js +1 -1
  210. package/build-module/preformatted/index.js.map +1 -1
  211. package/build-module/pullquote/deprecated.js +6 -7
  212. package/build-module/pullquote/deprecated.js.map +1 -1
  213. package/build-module/query/edit/enhanced-pagination-modal.js +50 -0
  214. package/build-module/query/edit/enhanced-pagination-modal.js.map +1 -0
  215. package/build-module/query/edit/inspector-controls/enhanced-pagination-control.js +35 -0
  216. package/build-module/query/edit/inspector-controls/enhanced-pagination-control.js.map +1 -0
  217. package/build-module/query/edit/inspector-controls/index.js +9 -26
  218. package/build-module/query/edit/inspector-controls/index.js.map +1 -1
  219. package/build-module/query/edit/query-content.js +8 -2
  220. package/build-module/query/edit/query-content.js.map +1 -1
  221. package/build-module/query/utils.js +17 -0
  222. package/build-module/query/utils.js.map +1 -1
  223. package/build-module/query/view.js +21 -6
  224. package/build-module/query/view.js.map +1 -1
  225. package/build-module/search/index.js +1 -0
  226. package/build-module/search/index.js.map +1 -1
  227. package/build-module/search/view.js +81 -151
  228. package/build-module/search/view.js.map +1 -1
  229. package/build-module/social-link/edit.native.js +3 -1
  230. package/build-module/social-link/edit.native.js.map +1 -1
  231. package/build-module/table/edit.js +7 -7
  232. package/build-module/table/edit.js.map +1 -1
  233. package/build-module/table-of-contents/edit.js +3 -131
  234. package/build-module/table-of-contents/edit.js.map +1 -1
  235. package/build-module/table-of-contents/hooks.js +137 -0
  236. package/build-module/table-of-contents/hooks.js.map +1 -0
  237. package/build-module/table-of-contents/index.js +2 -1
  238. package/build-module/table-of-contents/index.js.map +1 -1
  239. package/build-module/verse/edit.js +4 -1
  240. package/build-module/verse/edit.js.map +1 -1
  241. package/build-module/verse/index.js +1 -1
  242. package/build-module/verse/index.js.map +1 -1
  243. package/build-style/cover/style-rtl.css +9 -0
  244. package/build-style/cover/style.css +9 -0
  245. package/build-style/editor-rtl.css +15 -9
  246. package/build-style/editor.css +15 -9
  247. package/build-style/file/style-rtl.css +5 -0
  248. package/build-style/file/style.css +5 -0
  249. package/build-style/heading/style-rtl.css +13 -0
  250. package/build-style/heading/style.css +13 -0
  251. package/build-style/navigation-link/editor-rtl.css +0 -9
  252. package/build-style/navigation-link/editor.css +0 -9
  253. package/build-style/paragraph/editor-rtl.css +5 -0
  254. package/build-style/paragraph/editor.css +5 -0
  255. package/build-style/paragraph/style-rtl.css +5 -0
  256. package/build-style/paragraph/style.css +5 -0
  257. package/build-style/post-navigation-link/style-rtl.css +3 -0
  258. package/build-style/post-navigation-link/style.css +3 -0
  259. package/build-style/query/editor-rtl.css +10 -0
  260. package/build-style/query/editor.css +10 -0
  261. package/build-style/query/style-rtl.css +1 -1
  262. package/build-style/query/style.css +1 -1
  263. package/build-style/reset-rtl.css +27 -27
  264. package/build-style/reset.css +27 -27
  265. package/build-style/style-rtl.css +35 -0
  266. package/build-style/style.css +35 -0
  267. package/package.json +33 -34
  268. package/src/audio/test/__snapshots__/edit.native.js.snap +78 -106
  269. package/src/avatar/index.php +2 -2
  270. package/src/block/edit.js +58 -2
  271. package/src/block/test/edit.native.js +2 -3
  272. package/src/button/block.json +11 -2
  273. package/src/button/edit.js +27 -11
  274. package/src/button/save.js +10 -4
  275. package/src/buttons/edit.js +13 -3
  276. package/src/buttons/test/edit.native.js +28 -24
  277. package/src/calendar/index.php +2 -2
  278. package/src/code/block.json +2 -1
  279. package/src/code/edit.js +13 -1
  280. package/src/code/index.js +5 -0
  281. package/src/column/block.json +1 -0
  282. package/src/columns/block.json +2 -0
  283. package/src/comment-template/index.php +1 -1
  284. package/src/comments-pagination-next/index.php +1 -1
  285. package/src/comments-pagination-previous/index.php +1 -1
  286. package/src/cover/style.scss +12 -1
  287. package/src/cover/test/edit.js +10 -10
  288. package/src/cover/test/edit.native.js +18 -27
  289. package/src/embed/test/index.native.js +30 -45
  290. package/src/file/block.json +2 -1
  291. package/src/file/edit.native.js +1 -1
  292. package/src/file/index.php +21 -21
  293. package/src/file/style.scss +6 -1
  294. package/src/file/test/__snapshots__/edit.native.js.snap +162 -218
  295. package/src/file/utils/index.js +0 -15
  296. package/src/file/view.js +14 -5
  297. package/src/footnotes/edit.js +13 -1
  298. package/src/gallery/edit.js +1 -1
  299. package/src/gallery/index.php +1 -1
  300. package/src/group/block.json +4 -0
  301. package/src/group/edit.js +0 -1
  302. package/src/heading/block.json +2 -0
  303. package/src/heading/edit.js +0 -1
  304. package/src/heading/style.scss +4 -0
  305. package/src/heading/transforms.js +1 -6
  306. package/src/image/block.json +7 -4
  307. package/src/image/deprecated.js +210 -7
  308. package/src/image/edit.js +43 -29
  309. package/src/image/image.js +86 -43
  310. package/src/image/index.php +253 -28
  311. package/src/latest-posts/index.php +1 -1
  312. package/src/list/deprecated.js +84 -3
  313. package/src/list/edit.js +6 -3
  314. package/src/list/ordered-list-settings.js +20 -5
  315. package/src/list/save.js +10 -1
  316. package/src/list/test/edit.native.js +2 -4
  317. package/src/list/utils.js +22 -1
  318. package/src/navigation/block.json +4 -2
  319. package/src/navigation/constants.js +1 -0
  320. package/src/navigation/index.php +87 -123
  321. package/src/navigation/view.js +192 -96
  322. package/src/navigation-link/edit.js +21 -36
  323. package/src/navigation-link/editor.scss +0 -8
  324. package/src/navigation-link/transforms.js +22 -0
  325. package/src/page-list/edit.js +2 -1
  326. package/src/paragraph/editor.scss +5 -0
  327. package/src/paragraph/style.scss +5 -0
  328. package/src/pattern/edit.js +1 -0
  329. package/src/pattern/index.php +5 -5
  330. package/src/post-comments-form/edit.js +10 -0
  331. package/src/post-comments-form/form.js +7 -1
  332. package/src/post-content/block.json +3 -0
  333. package/src/post-content/edit.js +14 -6
  334. package/src/post-excerpt/index.php +2 -2
  335. package/src/post-featured-image/index.php +2 -2
  336. package/src/post-featured-image/overlay.js +1 -0
  337. package/src/post-navigation-link/index.php +0 -5
  338. package/src/post-navigation-link/style.scss +4 -0
  339. package/src/post-template/index.php +1 -1
  340. package/src/post-terms/index.php +5 -2
  341. package/src/preformatted/edit.js +5 -0
  342. package/src/preformatted/index.js +1 -1
  343. package/src/pullquote/deprecated.js +8 -13
  344. package/src/query/edit/enhanced-pagination-modal.js +65 -0
  345. package/src/query/edit/inspector-controls/enhanced-pagination-control.js +49 -0
  346. package/src/query/edit/inspector-controls/index.js +9 -45
  347. package/src/query/edit/query-content.js +8 -0
  348. package/src/query/editor.scss +10 -0
  349. package/src/query/index.php +31 -16
  350. package/src/query/style.scss +2 -2
  351. package/src/query/utils.js +22 -0
  352. package/src/query/view.js +19 -10
  353. package/src/query-pagination-next/index.php +2 -1
  354. package/src/query-pagination-previous/index.php +2 -1
  355. package/src/reset.scss +1 -1
  356. package/src/search/block.json +1 -0
  357. package/src/search/index.php +47 -4
  358. package/src/search/test/__snapshots__/edit.native.js.snap +265 -363
  359. package/src/search/view.js +70 -169
  360. package/src/social-link/edit.native.js +1 -1
  361. package/src/social-link/editor.native.scss +4 -0
  362. package/src/table/edit.js +21 -19
  363. package/src/table-of-contents/block.json +2 -1
  364. package/src/table-of-contents/edit.js +5 -162
  365. package/src/table-of-contents/hooks.js +156 -0
  366. package/src/verse/edit.js +5 -0
  367. package/src/verse/index.js +1 -1
  368. package/src/verse/test/edit.native.js +2 -3
  369. package/build/file/view-interactivity.js +0 -22
  370. package/build/file/view-interactivity.js.map +0 -1
  371. package/build/image/view-interactivity.js.map +0 -1
  372. package/build/navigation/view-interactivity.js +0 -172
  373. package/build/navigation/view-interactivity.js.map +0 -1
  374. package/build/navigation/view-modal.js +0 -115
  375. package/build/navigation/view-modal.js.map +0 -1
  376. package/build-module/file/view-interactivity.js +0 -18
  377. package/build-module/file/view-interactivity.js.map +0 -1
  378. package/build-module/image/view-interactivity.js.map +0 -1
  379. package/build-module/navigation/view-interactivity.js +0 -169
  380. package/build-module/navigation/view-interactivity.js.map +0 -1
  381. package/build-module/navigation/view-modal.js +0 -112
  382. package/build-module/navigation/view-modal.js.map +0 -1
  383. package/src/file/view-interactivity.js +0 -18
  384. package/src/navigation/view-interactivity.js +0 -196
  385. package/src/navigation/view-modal.js +0 -127
  386. /package/src/image/{view-interactivity.js → view.js} +0 -0
@@ -1,172 +1,73 @@
1
- /*eslint-env browser*/
2
-
3
- /** @type {?HTMLFormElement} */
4
- let expandedSearchBlock = null;
5
-
6
- const hiddenClass = 'wp-block-search__searchfield-hidden';
7
-
8
- /**
9
- * Toggles aria-label with data-toggled-aria-label.
10
- *
11
- * @param {HTMLElement} element
12
- */
13
- function toggleAriaLabel( element ) {
14
- if ( ! ( 'toggledAriaLabel' in element.dataset ) ) {
15
- throw new Error( 'Element lacks toggledAriaLabel in dataset.' );
16
- }
17
-
18
- const ariaLabel = element.dataset.toggledAriaLabel;
19
- element.dataset.toggledAriaLabel = element.ariaLabel;
20
- element.ariaLabel = ariaLabel;
21
- }
22
-
23
- /**
24
- * Gets search input.
25
- *
26
- * @param {HTMLFormElement} block Search block.
27
- * @return {HTMLInputElement} Search input.
28
- */
29
- function getSearchInput( block ) {
30
- return block.querySelector( '.wp-block-search__input' );
31
- }
32
-
33
- /**
34
- * Gets search button.
35
- *
36
- * @param {HTMLFormElement} block Search block.
37
- * @return {HTMLButtonElement} Search button.
38
- */
39
- function getSearchButton( block ) {
40
- return block.querySelector( '.wp-block-search__button' );
41
- }
42
-
43
- /**
44
- * Handles keydown event to collapse an expanded Search block (when pressing Escape key).
45
- *
46
- * @param {KeyboardEvent} event
47
- */
48
- function handleKeydownEvent( event ) {
49
- if ( ! expandedSearchBlock ) {
50
- // In case the event listener wasn't removed in time.
51
- return;
52
- }
53
-
54
- if ( event.key === 'Escape' ) {
55
- const block = expandedSearchBlock; // This is nullified by collapseExpandedSearchBlock().
56
- collapseExpandedSearchBlock();
57
- getSearchButton( block ).focus();
58
- }
59
- }
60
-
61
- /**
62
- * Handles keyup event to collapse an expanded Search block (e.g. when tabbing out of expanded Search block).
63
- *
64
- * @param {KeyboardEvent} event
65
- */
66
- function handleKeyupEvent( event ) {
67
- if ( ! expandedSearchBlock ) {
68
- // In case the event listener wasn't removed in time.
69
- return;
70
- }
71
-
72
- if ( event.target.closest( '.wp-block-search' ) !== expandedSearchBlock ) {
73
- collapseExpandedSearchBlock();
74
- }
75
- }
76
-
77
- /**
78
- * Expands search block.
79
- *
80
- * Inverse of what is done in collapseExpandedSearchBlock().
81
- *
82
- * @param {HTMLFormElement} block Search block.
83
- */
84
- function expandSearchBlock( block ) {
85
- // Make sure only one is open at a time.
86
- if ( expandedSearchBlock ) {
87
- collapseExpandedSearchBlock();
88
- }
89
-
90
- const searchField = getSearchInput( block );
91
- const searchButton = getSearchButton( block );
92
-
93
- searchButton.type = 'submit';
94
- searchField.ariaHidden = 'false';
95
- searchField.tabIndex = 0;
96
- searchButton.ariaExpanded = 'true';
97
- searchButton.removeAttribute( 'aria-controls' ); // Note: Seemingly not reflected with searchButton.ariaControls.
98
- toggleAriaLabel( searchButton );
99
- block.classList.remove( hiddenClass );
100
-
101
- searchField.focus(); // Note that Chrome seems to do this automatically.
102
-
103
- // The following two must be inverse of what is done in collapseExpandedSearchBlock().
104
- document.addEventListener( 'keydown', handleKeydownEvent, {
105
- passive: true,
106
- } );
107
- document.addEventListener( 'keyup', handleKeyupEvent, {
108
- passive: true,
109
- } );
110
-
111
- expandedSearchBlock = block;
112
- }
113
-
114
1
  /**
115
- * Collapses the expanded search block.
116
- *
117
- * Inverse of what is done in expandSearchBlock().
2
+ * WordPress dependencies
118
3
  */
119
- function collapseExpandedSearchBlock() {
120
- if ( ! expandedSearchBlock ) {
121
- throw new Error( 'Expected expandedSearchBlock to be defined.' );
122
- }
123
- const block = expandedSearchBlock;
124
- const searchField = getSearchInput( block );
125
- const searchButton = getSearchButton( block );
126
-
127
- searchButton.type = 'button';
128
- searchField.ariaHidden = 'true';
129
- searchField.tabIndex = -1;
130
- searchButton.ariaExpanded = 'false';
131
- searchButton.setAttribute( 'aria-controls', searchField.id ); // Note: Seemingly not reflected with searchButton.ariaControls.
132
- toggleAriaLabel( searchButton );
133
- block.classList.add( hiddenClass );
134
-
135
- // The following two must be inverse of what is done in expandSearchBlock().
136
- document.removeEventListener( 'keydown', handleKeydownEvent, {
137
- passive: true,
138
- } );
139
- document.removeEventListener( 'keyup', handleKeyupEvent, {
140
- passive: true,
141
- } );
142
-
143
- expandedSearchBlock = null;
144
- }
145
-
146
- // Listen for click events anywhere on the document so this script can be loaded asynchronously in the head.
147
- document.addEventListener(
148
- 'click',
149
- ( event ) => {
150
- // Get the ancestor expandable Search block of the clicked element.
151
- const block = event.target.closest(
152
- '.wp-block-search__button-behavior-expand'
153
- );
154
-
155
- /*
156
- * If there is already an expanded search block and either the current click was not for a Search block or it was
157
- * for another block, then collapse the currently-expanded block.
158
- */
159
- if ( expandedSearchBlock && block !== expandedSearchBlock ) {
160
- collapseExpandedSearchBlock();
161
- }
162
-
163
- // If the click was on or inside a collapsed Search block, expand it.
164
- if (
165
- block instanceof HTMLFormElement &&
166
- block.classList.contains( hiddenClass )
167
- ) {
168
- expandSearchBlock( block );
169
- }
4
+ import { store as wpStore } from '@wordpress/interactivity';
5
+
6
+ wpStore( {
7
+ selectors: {
8
+ core: {
9
+ search: {
10
+ ariaLabel: ( { context } ) => {
11
+ const { ariaLabelCollapsed, ariaLabelExpanded } =
12
+ context.core.search;
13
+ return context.core.search.isSearchInputVisible
14
+ ? ariaLabelExpanded
15
+ : ariaLabelCollapsed;
16
+ },
17
+ ariaControls: ( { context } ) => {
18
+ return context.core.search.isSearchInputVisible
19
+ ? null
20
+ : context.core.search.inputId;
21
+ },
22
+ type: ( { context } ) => {
23
+ return context.core.search.isSearchInputVisible
24
+ ? 'submit'
25
+ : 'button';
26
+ },
27
+ tabindex: ( { context } ) => {
28
+ return context.core.search.isSearchInputVisible
29
+ ? '0'
30
+ : '-1';
31
+ },
32
+ },
33
+ },
34
+ },
35
+ actions: {
36
+ core: {
37
+ search: {
38
+ openSearchInput: ( { context, event, ref } ) => {
39
+ if ( ! context.core.search.isSearchInputVisible ) {
40
+ event.preventDefault();
41
+ context.core.search.isSearchInputVisible = true;
42
+ ref.parentElement.querySelector( 'input' ).focus();
43
+ }
44
+ },
45
+ closeSearchInput: ( { context } ) => {
46
+ context.core.search.isSearchInputVisible = false;
47
+ },
48
+ handleSearchKeydown: ( store ) => {
49
+ const { actions, event, ref } = store;
50
+ // If Escape close the menu.
51
+ if ( event?.key === 'Escape' ) {
52
+ actions.core.search.closeSearchInput( store );
53
+ ref.querySelector( 'button' ).focus();
54
+ }
55
+ },
56
+ handleSearchFocusout: ( store ) => {
57
+ const { actions, event, ref } = store;
58
+ // If focus is outside search form, and in the document, close menu
59
+ // event.target === The element losing focus
60
+ // event.relatedTarget === The element receiving focus (if any)
61
+ // When focusout is outside the document,
62
+ // `window.document.activeElement` doesn't change.
63
+ if (
64
+ ! ref.contains( event.relatedTarget ) &&
65
+ event.target !== window.document.activeElement
66
+ ) {
67
+ actions.core.search.closeSearchInput( store );
68
+ }
69
+ },
70
+ },
71
+ },
170
72
  },
171
- { passive: true }
172
- );
73
+ } );
@@ -158,7 +158,7 @@ const SocialLinkEdit = ( {
158
158
  );
159
159
 
160
160
  return (
161
- <View>
161
+ <View style={ styles.container }>
162
162
  { isSelected && (
163
163
  <>
164
164
  <BlockControls>
@@ -21,3 +21,7 @@
21
21
  .inactiveIconDark {
22
22
  background-color: $dark-quaternary;
23
23
  }
24
+
25
+ .container {
26
+ margin: $block-selected-margin;
27
+ }
package/src/table/edit.js CHANGED
@@ -349,7 +349,7 @@ function TableEdit( {
349
349
  useEffect( () => {
350
350
  if ( hasTableCreated ) {
351
351
  tableRef?.current
352
- ?.querySelector( 'td[contentEditable="true"]' )
352
+ ?.querySelector( 'td div[contentEditable="true"]' )
353
353
  ?.focus();
354
354
  setHasTableCreated( false );
355
355
  }
@@ -414,31 +414,33 @@ function TableEdit( {
414
414
  },
415
415
  columnIndex
416
416
  ) => (
417
- <RichText
418
- tagName={ CellTag }
417
+ <CellTag
419
418
  key={ columnIndex }
419
+ scope={ CellTag === 'th' ? scope : undefined }
420
+ colSpan={ colspan }
421
+ rowSpan={ rowspan }
420
422
  className={ classnames(
421
423
  {
422
424
  [ `has-text-align-${ align }` ]: align,
423
425
  },
424
426
  'wp-block-table__cell-content'
425
427
  ) }
426
- scope={ CellTag === 'th' ? scope : undefined }
427
- colSpan={ colspan }
428
- rowSpan={ rowspan }
429
- value={ content }
430
- onChange={ onChange }
431
- onFocus={ () => {
432
- setSelectedCell( {
433
- sectionName: name,
434
- rowIndex,
435
- columnIndex,
436
- type: 'cell',
437
- } );
438
- } }
439
- aria-label={ cellAriaLabel[ name ] }
440
- placeholder={ placeholder[ name ] }
441
- />
428
+ >
429
+ <RichText
430
+ value={ content }
431
+ onChange={ onChange }
432
+ onFocus={ () => {
433
+ setSelectedCell( {
434
+ sectionName: name,
435
+ rowIndex,
436
+ columnIndex,
437
+ type: 'cell',
438
+ } );
439
+ } }
440
+ aria-label={ cellAriaLabel[ name ] }
441
+ placeholder={ placeholder[ name ] }
442
+ />
443
+ </CellTag>
442
444
  )
443
445
  ) }
444
446
  </tr>
@@ -13,7 +13,8 @@
13
13
  "type": "array",
14
14
  "items": {
15
15
  "type": "object"
16
- }
16
+ },
17
+ "default": []
17
18
  },
18
19
  "onlyIncludeCurrentPage": {
19
20
  "type": "boolean",
@@ -1,8 +1,3 @@
1
- /**
2
- * External dependencies
3
- */
4
- import fastDeepEqual from 'fast-deep-equal/es6';
5
-
6
1
  /**
7
2
  * WordPress dependencies
8
3
  */
@@ -22,10 +17,8 @@ import {
22
17
  ToolbarGroup,
23
18
  } from '@wordpress/components';
24
19
  import { useDispatch, useSelect } from '@wordpress/data';
25
- import { __unstableStripHTML as stripHTML } from '@wordpress/dom';
26
- import { renderToString, useEffect } from '@wordpress/element';
20
+ import { renderToString } from '@wordpress/element';
27
21
  import { __ } from '@wordpress/i18n';
28
- import { addQueryArgs, removeQueryArgs } from '@wordpress/url';
29
22
 
30
23
  /**
31
24
  * Internal dependencies
@@ -33,6 +26,7 @@ import { addQueryArgs, removeQueryArgs } from '@wordpress/url';
33
26
  import icon from './icon';
34
27
  import TableOfContentsList from './list';
35
28
  import { linearToNestedHeadingList } from './utils';
29
+ import { useObserveHeadings } from './hooks';
36
30
 
37
31
  /** @typedef {import('./utils').HeadingData} HeadingData */
38
32
 
@@ -53,6 +47,8 @@ export default function TableOfContentsEdit( {
53
47
  clientId,
54
48
  setAttributes,
55
49
  } ) {
50
+ useObserveHeadings( clientId );
51
+
56
52
  const blockProps = useBlockProps();
57
53
 
58
54
  const canInsertList = useSelect(
@@ -66,160 +62,7 @@ export default function TableOfContentsEdit( {
66
62
  [ clientId ]
67
63
  );
68
64
 
69
- const { __unstableMarkNextChangeAsNotPersistent, replaceBlocks } =
70
- useDispatch( blockEditorStore );
71
-
72
- /**
73
- * The latest heading data, or null if the new data deeply equals the saved
74
- * headings attribute.
75
- *
76
- * Since useSelect forces a re-render when its return value is shallowly
77
- * inequal to its prior call, we would be re-rendering this block every time
78
- * the stores change, even if the latest headings were deeply equal to the
79
- * ones saved in the block attributes.
80
- *
81
- * By returning null when they're equal, we reduce that to 2 renders: one
82
- * when there are new latest headings (and so it returns them), and one when
83
- * they haven't changed (so it returns null). As long as the latest heading
84
- * data remains the same, further calls of the useSelect callback will
85
- * continue to return null, thus preventing any forced re-renders.
86
- */
87
- const latestHeadings = useSelect(
88
- ( select ) => {
89
- const {
90
- getBlockAttributes,
91
- getBlockName,
92
- getClientIdsWithDescendants,
93
- __experimentalGetGlobalBlocksByName: getGlobalBlocksByName,
94
- } = select( blockEditorStore );
95
-
96
- // FIXME: @wordpress/block-library should not depend on @wordpress/editor.
97
- // Blocks can be loaded into a *non-post* block editor, so to avoid
98
- // declaring @wordpress/editor as a dependency, we must access its
99
- // store by string. When the store is not available, editorSelectors
100
- // will be null, and the block's saved markup will lack permalinks.
101
- // eslint-disable-next-line @wordpress/data-no-store-string-literals
102
- const editorSelectors = select( 'core/editor' );
103
-
104
- const pageBreakClientIds = getGlobalBlocksByName( 'core/nextpage' );
105
-
106
- const isPaginated = pageBreakClientIds.length !== 0;
107
-
108
- // Get the client ids of all blocks in the editor.
109
- const allBlockClientIds = getClientIdsWithDescendants();
110
-
111
- // If onlyIncludeCurrentPage is true, calculate the page (of a paginated post) this block is part of, so we know which headings to include; otherwise, skip the calculation.
112
- let tocPage = 1;
113
-
114
- if ( isPaginated && onlyIncludeCurrentPage ) {
115
- // We can't use getBlockIndex because it only returns the index
116
- // relative to sibling blocks.
117
- const tocIndex = allBlockClientIds.indexOf( clientId );
118
-
119
- for ( const [
120
- blockIndex,
121
- blockClientId,
122
- ] of allBlockClientIds.entries() ) {
123
- // If we've reached blocks after the Table of Contents, we've
124
- // finished calculating which page the block is on.
125
- if ( blockIndex >= tocIndex ) {
126
- break;
127
- }
128
- if ( getBlockName( blockClientId ) === 'core/nextpage' ) {
129
- tocPage++;
130
- }
131
- }
132
- }
133
-
134
- const _latestHeadings = [];
135
-
136
- /** The page (of a paginated post) a heading will be part of. */
137
- let headingPage = 1;
138
-
139
- /**
140
- * A permalink to the current post. If the core/editor store is
141
- * unavailable, this variable will be null.
142
- */
143
- const permalink = editorSelectors?.getPermalink() ?? null;
144
-
145
- let headingPageLink = null;
146
-
147
- // If the core/editor store is available, we can add permalinks to the
148
- // generated table of contents.
149
- if ( typeof permalink === 'string' ) {
150
- headingPageLink = isPaginated
151
- ? addQueryArgs( permalink, { page: headingPage } )
152
- : permalink;
153
- }
154
-
155
- for ( const blockClientId of allBlockClientIds ) {
156
- const blockName = getBlockName( blockClientId );
157
- if ( blockName === 'core/nextpage' ) {
158
- headingPage++;
159
-
160
- // If we're only including headings from the current page (of
161
- // a paginated post), then exit the loop if we've reached the
162
- // pages after the one with the Table of Contents block.
163
- if ( onlyIncludeCurrentPage && headingPage > tocPage ) {
164
- break;
165
- }
166
-
167
- if ( typeof permalink === 'string' ) {
168
- headingPageLink = addQueryArgs(
169
- removeQueryArgs( permalink, [ 'page' ] ),
170
- { page: headingPage }
171
- );
172
- }
173
- }
174
- // If we're including all headings or we've reached headings on
175
- // the same page as the Table of Contents block, add them to the
176
- // list.
177
- else if (
178
- ! onlyIncludeCurrentPage ||
179
- headingPage === tocPage
180
- ) {
181
- if ( blockName === 'core/heading' ) {
182
- const headingAttributes =
183
- getBlockAttributes( blockClientId );
184
-
185
- const canBeLinked =
186
- typeof headingPageLink === 'string' &&
187
- typeof headingAttributes.anchor === 'string' &&
188
- headingAttributes.anchor !== '';
189
-
190
- _latestHeadings.push( {
191
- // Convert line breaks to spaces, and get rid of HTML tags in the headings.
192
- content: stripHTML(
193
- headingAttributes.content.replace(
194
- /(<br *\/?>)+/g,
195
- ' '
196
- )
197
- ),
198
- level: headingAttributes.level,
199
- link: canBeLinked
200
- ? `${ headingPageLink }#${ headingAttributes.anchor }`
201
- : null,
202
- } );
203
- }
204
- }
205
- }
206
-
207
- if ( fastDeepEqual( headings, _latestHeadings ) ) {
208
- return null;
209
- }
210
- return _latestHeadings;
211
- },
212
- [ clientId, onlyIncludeCurrentPage, headings ]
213
- );
214
-
215
- useEffect( () => {
216
- if ( latestHeadings !== null ) {
217
- // This is required to keep undo working and not create 2 undo steps
218
- // for each heading change.
219
- __unstableMarkNextChangeAsNotPersistent();
220
- setAttributes( { headings: latestHeadings } );
221
- }
222
- }, [ latestHeadings ] );
65
+ const { replaceBlocks } = useDispatch( blockEditorStore );
223
66
 
224
67
  const headingTree = linearToNestedHeadingList( headings );
225
68
 
@@ -0,0 +1,156 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import fastDeepEqual from 'fast-deep-equal/es6';
5
+
6
+ /**
7
+ * WordPress dependencies
8
+ */
9
+ import { useRegistry } from '@wordpress/data';
10
+ import { __unstableStripHTML as stripHTML } from '@wordpress/dom';
11
+ import { useEffect } from '@wordpress/element';
12
+ import { addQueryArgs, removeQueryArgs } from '@wordpress/url';
13
+ import { store as blockEditorStore } from '@wordpress/block-editor';
14
+
15
+ function getLatestHeadings( select, clientId ) {
16
+ const {
17
+ getBlockAttributes,
18
+ getBlockName,
19
+ getClientIdsWithDescendants,
20
+ __experimentalGetGlobalBlocksByName: getGlobalBlocksByName,
21
+ } = select( blockEditorStore );
22
+
23
+ // FIXME: @wordpress/block-library should not depend on @wordpress/editor.
24
+ // Blocks can be loaded into a *non-post* block editor, so to avoid
25
+ // declaring @wordpress/editor as a dependency, we must access its
26
+ // store by string. When the store is not available, editorSelectors
27
+ // will be null, and the block's saved markup will lack permalinks.
28
+ // eslint-disable-next-line @wordpress/data-no-store-string-literals
29
+ const permalink = select( 'core/editor' ).getPermalink() ?? null;
30
+
31
+ const isPaginated = getGlobalBlocksByName( 'core/nextpage' ).length !== 0;
32
+ const { onlyIncludeCurrentPage } = getBlockAttributes( clientId ) ?? {};
33
+
34
+ // Get the client ids of all blocks in the editor.
35
+ const allBlockClientIds = getClientIdsWithDescendants();
36
+
37
+ // If onlyIncludeCurrentPage is true, calculate the page (of a paginated post) this block is part of, so we know which headings to include; otherwise, skip the calculation.
38
+ let tocPage = 1;
39
+
40
+ if ( isPaginated && onlyIncludeCurrentPage ) {
41
+ // We can't use getBlockIndex because it only returns the index
42
+ // relative to sibling blocks.
43
+ const tocIndex = allBlockClientIds.indexOf( clientId );
44
+
45
+ for ( const [
46
+ blockIndex,
47
+ blockClientId,
48
+ ] of allBlockClientIds.entries() ) {
49
+ // If we've reached blocks after the Table of Contents, we've
50
+ // finished calculating which page the block is on.
51
+ if ( blockIndex >= tocIndex ) {
52
+ break;
53
+ }
54
+ if ( getBlockName( blockClientId ) === 'core/nextpage' ) {
55
+ tocPage++;
56
+ }
57
+ }
58
+ }
59
+
60
+ const latestHeadings = [];
61
+
62
+ /** The page (of a paginated post) a heading will be part of. */
63
+ let headingPage = 1;
64
+ let headingPageLink = null;
65
+
66
+ // If the core/editor store is available, we can add permalinks to the
67
+ // generated table of contents.
68
+ if ( typeof permalink === 'string' ) {
69
+ headingPageLink = isPaginated
70
+ ? addQueryArgs( permalink, { page: headingPage } )
71
+ : permalink;
72
+ }
73
+
74
+ for ( const blockClientId of allBlockClientIds ) {
75
+ const blockName = getBlockName( blockClientId );
76
+ if ( blockName === 'core/nextpage' ) {
77
+ headingPage++;
78
+
79
+ // If we're only including headings from the current page (of
80
+ // a paginated post), then exit the loop if we've reached the
81
+ // pages after the one with the Table of Contents block.
82
+ if ( onlyIncludeCurrentPage && headingPage > tocPage ) {
83
+ break;
84
+ }
85
+
86
+ if ( typeof permalink === 'string' ) {
87
+ headingPageLink = addQueryArgs(
88
+ removeQueryArgs( permalink, [ 'page' ] ),
89
+ { page: headingPage }
90
+ );
91
+ }
92
+ }
93
+ // If we're including all headings or we've reached headings on
94
+ // the same page as the Table of Contents block, add them to the
95
+ // list.
96
+ else if ( ! onlyIncludeCurrentPage || headingPage === tocPage ) {
97
+ if ( blockName === 'core/heading' ) {
98
+ const headingAttributes = getBlockAttributes( blockClientId );
99
+
100
+ const canBeLinked =
101
+ typeof headingPageLink === 'string' &&
102
+ typeof headingAttributes.anchor === 'string' &&
103
+ headingAttributes.anchor !== '';
104
+
105
+ latestHeadings.push( {
106
+ // Convert line breaks to spaces, and get rid of HTML tags in the headings.
107
+ content: stripHTML(
108
+ headingAttributes.content.replace(
109
+ /(<br *\/?>)+/g,
110
+ ' '
111
+ )
112
+ ),
113
+ level: headingAttributes.level,
114
+ link: canBeLinked
115
+ ? `${ headingPageLink }#${ headingAttributes.anchor }`
116
+ : null,
117
+ } );
118
+ }
119
+ }
120
+ }
121
+
122
+ return latestHeadings;
123
+ }
124
+
125
+ function observeCallback( select, dispatch, clientId ) {
126
+ const { getBlockAttributes } = select( blockEditorStore );
127
+ const { updateBlockAttributes, __unstableMarkNextChangeAsNotPersistent } =
128
+ dispatch( blockEditorStore );
129
+
130
+ /**
131
+ * If the block no longer exists in the store, skip the update.
132
+ * The "undo" action recreates the block and provides a new `clientId`.
133
+ * The hook still might be observing the changes while the old block unmounts.
134
+ */
135
+ const attributes = getBlockAttributes( clientId );
136
+ if ( attributes === null ) {
137
+ return;
138
+ }
139
+
140
+ const headings = getLatestHeadings( select, clientId );
141
+ if ( ! fastDeepEqual( headings, attributes.headings ) ) {
142
+ __unstableMarkNextChangeAsNotPersistent();
143
+ updateBlockAttributes( clientId, { headings } );
144
+ }
145
+ }
146
+
147
+ export function useObserveHeadings( clientId ) {
148
+ const registry = useRegistry();
149
+ useEffect( () => {
150
+ // Todo: Limit subscription to block editor store when data no longer depends on `getPermalink`.
151
+ // See: https://github.com/WordPress/gutenberg/pull/45513
152
+ return registry.subscribe( () =>
153
+ observeCallback( registry.select, registry.dispatch, clientId )
154
+ );
155
+ }, [ registry, clientId ] );
156
+ }