@wordpress/block-library 8.18.1-next.5a1d1283.0 → 8.19.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 (381) 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/post-comments-form/edit.js +10 -2
  76. package/build/post-comments-form/edit.js.map +1 -1
  77. package/build/post-comments-form/form.js +5 -3
  78. package/build/post-comments-form/form.js.map +1 -1
  79. package/build/post-content/edit.js +8 -7
  80. package/build/post-content/edit.js.map +1 -1
  81. package/build/post-content/index.js +3 -0
  82. package/build/post-content/index.js.map +1 -1
  83. package/build/post-featured-image/overlay.js +2 -1
  84. package/build/post-featured-image/overlay.js.map +1 -1
  85. package/build/preformatted/edit.js +4 -1
  86. package/build/preformatted/edit.js.map +1 -1
  87. package/build/preformatted/index.js +1 -1
  88. package/build/preformatted/index.js.map +1 -1
  89. package/build/pullquote/deprecated.js +6 -7
  90. package/build/pullquote/deprecated.js.map +1 -1
  91. package/build/query/edit/enhanced-pagination-modal.js +56 -0
  92. package/build/query/edit/enhanced-pagination-modal.js.map +1 -0
  93. package/build/query/edit/inspector-controls/enhanced-pagination-control.js +42 -0
  94. package/build/query/edit/inspector-controls/enhanced-pagination-control.js.map +1 -0
  95. package/build/query/edit/inspector-controls/index.js +8 -25
  96. package/build/query/edit/inspector-controls/index.js.map +1 -1
  97. package/build/query/edit/query-content.js +8 -2
  98. package/build/query/edit/query-content.js.map +1 -1
  99. package/build/query/utils.js +19 -0
  100. package/build/query/utils.js.map +1 -1
  101. package/build/query/view.js +4 -5
  102. package/build/query/view.js.map +1 -1
  103. package/build/search/index.js +1 -0
  104. package/build/search/index.js.map +1 -1
  105. package/build/search/view.js +81 -150
  106. package/build/search/view.js.map +1 -1
  107. package/build/social-link/edit.native.js +3 -1
  108. package/build/social-link/edit.native.js.map +1 -1
  109. package/build/table/edit.js +7 -7
  110. package/build/table/edit.js.map +1 -1
  111. package/build/table-of-contents/edit.js +2 -130
  112. package/build/table-of-contents/edit.js.map +1 -1
  113. package/build/table-of-contents/hooks.js +145 -0
  114. package/build/table-of-contents/hooks.js.map +1 -0
  115. package/build/table-of-contents/index.js +2 -1
  116. package/build/table-of-contents/index.js.map +1 -1
  117. package/build/verse/edit.js +4 -1
  118. package/build/verse/edit.js.map +1 -1
  119. package/build/verse/index.js +1 -1
  120. package/build/verse/index.js.map +1 -1
  121. package/build-module/block/edit.js +54 -3
  122. package/build-module/block/edit.js.map +1 -1
  123. package/build-module/button/edit.js +7 -4
  124. package/build-module/button/edit.js.map +1 -1
  125. package/build-module/button/index.js +11 -2
  126. package/build-module/button/index.js.map +1 -1
  127. package/build-module/button/save.js +10 -4
  128. package/build-module/button/save.js.map +1 -1
  129. package/build-module/buttons/edit.js +12 -3
  130. package/build-module/buttons/edit.js.map +1 -1
  131. package/build-module/code/edit.js +8 -2
  132. package/build-module/code/edit.js.map +1 -1
  133. package/build-module/code/index.js +7 -1
  134. package/build-module/code/index.js.map +1 -1
  135. package/build-module/column/index.js +1 -0
  136. package/build-module/column/index.js.map +1 -1
  137. package/build-module/columns/index.js +2 -0
  138. package/build-module/columns/index.js.map +1 -1
  139. package/build-module/file/edit.native.js +1 -1
  140. package/build-module/file/edit.native.js.map +1 -1
  141. package/build-module/file/index.js +2 -1
  142. package/build-module/file/index.js.map +1 -1
  143. package/build-module/file/utils/index.js +0 -13
  144. package/build-module/file/utils/index.js.map +1 -1
  145. package/build-module/file/view.js +14 -2
  146. package/build-module/file/view.js.map +1 -1
  147. package/build-module/footnotes/edit.js +12 -2
  148. package/build-module/footnotes/edit.js.map +1 -1
  149. package/build-module/gallery/edit.js +1 -1
  150. package/build-module/gallery/edit.js.map +1 -1
  151. package/build-module/group/edit.js +0 -1
  152. package/build-module/group/edit.js.map +1 -1
  153. package/build-module/group/index.js +4 -0
  154. package/build-module/group/index.js.map +1 -1
  155. package/build-module/heading/edit.js +0 -1
  156. package/build-module/heading/edit.js.map +1 -1
  157. package/build-module/heading/index.js +2 -0
  158. package/build-module/heading/index.js.map +1 -1
  159. package/build-module/heading/transforms.js +3 -6
  160. package/build-module/heading/transforms.js.map +1 -1
  161. package/build-module/image/deprecated.js +191 -7
  162. package/build-module/image/deprecated.js.map +1 -1
  163. package/build-module/image/edit.js +27 -12
  164. package/build-module/image/edit.js.map +1 -1
  165. package/build-module/image/image.js +77 -42
  166. package/build-module/image/image.js.map +1 -1
  167. package/build-module/image/index.js +7 -4
  168. package/build-module/image/index.js.map +1 -1
  169. package/build-module/image/{view-interactivity.js → view.js} +1 -1
  170. package/build-module/image/view.js.map +1 -0
  171. package/build-module/list/deprecated.js +95 -3
  172. package/build-module/list/deprecated.js.map +1 -1
  173. package/build-module/list/edit.js +10 -10
  174. package/build-module/list/edit.js.map +1 -1
  175. package/build-module/list/ordered-list-settings.js +10 -10
  176. package/build-module/list/ordered-list-settings.js.map +1 -1
  177. package/build-module/list/save.js +4 -2
  178. package/build-module/list/save.js.map +1 -1
  179. package/build-module/list/utils.js +20 -2
  180. package/build-module/list/utils.js.map +1 -1
  181. package/build-module/navigation/constants.js +1 -1
  182. package/build-module/navigation/constants.js.map +1 -1
  183. package/build-module/navigation/index.js +4 -2
  184. package/build-module/navigation/index.js.map +1 -1
  185. package/build-module/navigation/view.js +168 -83
  186. package/build-module/navigation/view.js.map +1 -1
  187. package/build-module/navigation-link/edit.js +3 -9
  188. package/build-module/navigation-link/edit.js.map +1 -1
  189. package/build-module/navigation-link/transforms.js +24 -0
  190. package/build-module/navigation-link/transforms.js.map +1 -1
  191. package/build-module/page-list/edit.js +2 -1
  192. package/build-module/page-list/edit.js.map +1 -1
  193. package/build-module/post-comments-form/edit.js +10 -2
  194. package/build-module/post-comments-form/edit.js.map +1 -1
  195. package/build-module/post-comments-form/form.js +5 -3
  196. package/build-module/post-comments-form/form.js.map +1 -1
  197. package/build-module/post-content/edit.js +8 -7
  198. package/build-module/post-content/edit.js.map +1 -1
  199. package/build-module/post-content/index.js +3 -0
  200. package/build-module/post-content/index.js.map +1 -1
  201. package/build-module/post-featured-image/overlay.js +2 -1
  202. package/build-module/post-featured-image/overlay.js.map +1 -1
  203. package/build-module/preformatted/edit.js +4 -1
  204. package/build-module/preformatted/edit.js.map +1 -1
  205. package/build-module/preformatted/index.js +1 -1
  206. package/build-module/preformatted/index.js.map +1 -1
  207. package/build-module/pullquote/deprecated.js +6 -7
  208. package/build-module/pullquote/deprecated.js.map +1 -1
  209. package/build-module/query/edit/enhanced-pagination-modal.js +50 -0
  210. package/build-module/query/edit/enhanced-pagination-modal.js.map +1 -0
  211. package/build-module/query/edit/inspector-controls/enhanced-pagination-control.js +35 -0
  212. package/build-module/query/edit/inspector-controls/enhanced-pagination-control.js.map +1 -0
  213. package/build-module/query/edit/inspector-controls/index.js +9 -26
  214. package/build-module/query/edit/inspector-controls/index.js.map +1 -1
  215. package/build-module/query/edit/query-content.js +8 -2
  216. package/build-module/query/edit/query-content.js.map +1 -1
  217. package/build-module/query/utils.js +17 -0
  218. package/build-module/query/utils.js.map +1 -1
  219. package/build-module/query/view.js +4 -5
  220. package/build-module/query/view.js.map +1 -1
  221. package/build-module/search/index.js +1 -0
  222. package/build-module/search/index.js.map +1 -1
  223. package/build-module/search/view.js +81 -151
  224. package/build-module/search/view.js.map +1 -1
  225. package/build-module/social-link/edit.native.js +3 -1
  226. package/build-module/social-link/edit.native.js.map +1 -1
  227. package/build-module/table/edit.js +7 -7
  228. package/build-module/table/edit.js.map +1 -1
  229. package/build-module/table-of-contents/edit.js +3 -131
  230. package/build-module/table-of-contents/edit.js.map +1 -1
  231. package/build-module/table-of-contents/hooks.js +137 -0
  232. package/build-module/table-of-contents/hooks.js.map +1 -0
  233. package/build-module/table-of-contents/index.js +2 -1
  234. package/build-module/table-of-contents/index.js.map +1 -1
  235. package/build-module/verse/edit.js +4 -1
  236. package/build-module/verse/edit.js.map +1 -1
  237. package/build-module/verse/index.js +1 -1
  238. package/build-module/verse/index.js.map +1 -1
  239. package/build-style/cover/style-rtl.css +9 -0
  240. package/build-style/cover/style.css +9 -0
  241. package/build-style/editor-rtl.css +15 -9
  242. package/build-style/editor.css +15 -9
  243. package/build-style/file/style-rtl.css +5 -0
  244. package/build-style/file/style.css +5 -0
  245. package/build-style/heading/style-rtl.css +13 -0
  246. package/build-style/heading/style.css +13 -0
  247. package/build-style/navigation-link/editor-rtl.css +0 -9
  248. package/build-style/navigation-link/editor.css +0 -9
  249. package/build-style/paragraph/editor-rtl.css +5 -0
  250. package/build-style/paragraph/editor.css +5 -0
  251. package/build-style/paragraph/style-rtl.css +5 -0
  252. package/build-style/paragraph/style.css +5 -0
  253. package/build-style/post-navigation-link/style-rtl.css +3 -0
  254. package/build-style/post-navigation-link/style.css +3 -0
  255. package/build-style/query/editor-rtl.css +10 -0
  256. package/build-style/query/editor.css +10 -0
  257. package/build-style/query/style-rtl.css +1 -1
  258. package/build-style/query/style.css +1 -1
  259. package/build-style/reset-rtl.css +27 -27
  260. package/build-style/reset.css +27 -27
  261. package/build-style/style-rtl.css +35 -0
  262. package/build-style/style.css +35 -0
  263. package/package.json +32 -33
  264. package/src/audio/test/__snapshots__/edit.native.js.snap +78 -106
  265. package/src/avatar/index.php +2 -2
  266. package/src/block/edit.js +58 -2
  267. package/src/block/test/edit.native.js +2 -3
  268. package/src/button/block.json +11 -2
  269. package/src/button/edit.js +27 -11
  270. package/src/button/save.js +10 -4
  271. package/src/buttons/edit.js +13 -3
  272. package/src/buttons/test/edit.native.js +28 -24
  273. package/src/calendar/index.php +2 -2
  274. package/src/code/block.json +2 -1
  275. package/src/code/edit.js +13 -1
  276. package/src/code/index.js +5 -0
  277. package/src/column/block.json +1 -0
  278. package/src/columns/block.json +2 -0
  279. package/src/comment-template/index.php +1 -1
  280. package/src/comments-pagination-next/index.php +1 -1
  281. package/src/comments-pagination-previous/index.php +1 -1
  282. package/src/cover/style.scss +12 -1
  283. package/src/cover/test/edit.js +7 -7
  284. package/src/cover/test/edit.native.js +18 -27
  285. package/src/embed/test/index.native.js +30 -45
  286. package/src/file/block.json +2 -1
  287. package/src/file/edit.native.js +1 -1
  288. package/src/file/index.php +19 -21
  289. package/src/file/style.scss +6 -1
  290. package/src/file/test/__snapshots__/edit.native.js.snap +162 -218
  291. package/src/file/utils/index.js +0 -15
  292. package/src/file/view.js +14 -5
  293. package/src/footnotes/edit.js +13 -1
  294. package/src/gallery/edit.js +1 -1
  295. package/src/gallery/index.php +1 -1
  296. package/src/group/block.json +4 -0
  297. package/src/group/edit.js +0 -1
  298. package/src/heading/block.json +2 -0
  299. package/src/heading/edit.js +0 -1
  300. package/src/heading/style.scss +4 -0
  301. package/src/heading/transforms.js +1 -6
  302. package/src/image/block.json +7 -4
  303. package/src/image/deprecated.js +210 -7
  304. package/src/image/edit.js +43 -29
  305. package/src/image/image.js +86 -43
  306. package/src/image/index.php +251 -28
  307. package/src/latest-posts/index.php +1 -1
  308. package/src/list/deprecated.js +84 -3
  309. package/src/list/edit.js +6 -3
  310. package/src/list/ordered-list-settings.js +20 -5
  311. package/src/list/save.js +10 -1
  312. package/src/list/test/edit.native.js +2 -4
  313. package/src/list/utils.js +22 -1
  314. package/src/navigation/block.json +4 -2
  315. package/src/navigation/constants.js +1 -0
  316. package/src/navigation/index.php +85 -123
  317. package/src/navigation/view.js +192 -96
  318. package/src/navigation-link/edit.js +21 -36
  319. package/src/navigation-link/editor.scss +0 -8
  320. package/src/navigation-link/transforms.js +22 -0
  321. package/src/page-list/edit.js +2 -1
  322. package/src/paragraph/editor.scss +5 -0
  323. package/src/paragraph/style.scss +5 -0
  324. package/src/pattern/index.php +2 -2
  325. package/src/post-comments-form/edit.js +10 -0
  326. package/src/post-comments-form/form.js +7 -1
  327. package/src/post-content/block.json +3 -0
  328. package/src/post-content/edit.js +14 -6
  329. package/src/post-excerpt/index.php +2 -2
  330. package/src/post-featured-image/index.php +2 -2
  331. package/src/post-featured-image/overlay.js +1 -0
  332. package/src/post-navigation-link/index.php +0 -5
  333. package/src/post-navigation-link/style.scss +4 -0
  334. package/src/post-template/index.php +1 -1
  335. package/src/post-terms/index.php +5 -2
  336. package/src/preformatted/edit.js +5 -0
  337. package/src/preformatted/index.js +1 -1
  338. package/src/pullquote/deprecated.js +8 -13
  339. package/src/query/edit/enhanced-pagination-modal.js +65 -0
  340. package/src/query/edit/inspector-controls/enhanced-pagination-control.js +49 -0
  341. package/src/query/edit/inspector-controls/index.js +9 -45
  342. package/src/query/edit/query-content.js +8 -0
  343. package/src/query/editor.scss +10 -0
  344. package/src/query/index.php +29 -16
  345. package/src/query/style.scss +2 -2
  346. package/src/query/utils.js +22 -0
  347. package/src/query/view.js +5 -5
  348. package/src/query-pagination-next/index.php +1 -1
  349. package/src/query-pagination-previous/index.php +1 -1
  350. package/src/reset.scss +1 -1
  351. package/src/search/block.json +1 -0
  352. package/src/search/index.php +45 -4
  353. package/src/search/test/__snapshots__/edit.native.js.snap +265 -363
  354. package/src/search/view.js +70 -169
  355. package/src/social-link/edit.native.js +1 -1
  356. package/src/social-link/editor.native.scss +4 -0
  357. package/src/table/edit.js +21 -19
  358. package/src/table-of-contents/block.json +2 -1
  359. package/src/table-of-contents/edit.js +5 -162
  360. package/src/table-of-contents/hooks.js +156 -0
  361. package/src/verse/edit.js +5 -0
  362. package/src/verse/index.js +1 -1
  363. package/src/verse/test/edit.native.js +2 -3
  364. package/build/file/view-interactivity.js +0 -22
  365. package/build/file/view-interactivity.js.map +0 -1
  366. package/build/image/view-interactivity.js.map +0 -1
  367. package/build/navigation/view-interactivity.js +0 -172
  368. package/build/navigation/view-interactivity.js.map +0 -1
  369. package/build/navigation/view-modal.js +0 -115
  370. package/build/navigation/view-modal.js.map +0 -1
  371. package/build-module/file/view-interactivity.js +0 -18
  372. package/build-module/file/view-interactivity.js.map +0 -1
  373. package/build-module/image/view-interactivity.js.map +0 -1
  374. package/build-module/navigation/view-interactivity.js +0 -169
  375. package/build-module/navigation/view-interactivity.js.map +0 -1
  376. package/build-module/navigation/view-modal.js +0 -112
  377. package/build-module/navigation/view-modal.js.map +0 -1
  378. package/src/file/view-interactivity.js +0 -18
  379. package/src/navigation/view-interactivity.js +0 -196
  380. package/src/navigation/view-modal.js +0 -127
  381. /package/src/image/{view-interactivity.js → view.js} +0 -0
@@ -67,99 +67,61 @@ if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) {
67
67
  }
68
68
  }
69
69
 
70
- if ( gutenberg_should_block_use_interactivity_api( 'core/navigation' ) ) {
71
70
 
72
- /**
73
- * Add Interactivity API directives to the navigation-submenu and page-list blocks markup using the Tag Processor
74
- * The final HTML of the navigation-submenu and the page-list blocks will look similar to this:
75
- *
76
- * <li
77
- * class="has-child"
78
- * data-wp-context='{ "core": { "navigation": { "isMenuOpen": false, "overlay": false } } }'
79
- * data-wp-effect="effects.core.navigation.initMenu"
80
- * data-wp-on.keydown="actions.core.navigation.handleMenuKeydown"
81
- * data-wp-on.focusout="actions.core.navigation.handleMenuFocusout"
82
- * >
83
- * <button
84
- * class="wp-block-navigation-submenu__toggle"
85
- * data-wp-on.click="actions.core.navigation.openMenu"
86
- * data-wp-bind.aria-expanded="context.core.navigation.isMenuOpen"
87
- * >
88
- * </button>
89
- * <span>Title</span>
90
- * <ul class="wp-block-navigation__submenu-container">
91
- * SUBMENU ITEMS
92
- * </ul>
93
- * </li>
94
- *
95
- * @param string $w Markup of the navigation block.
96
- * @param array $block_attributes Block attributes.
97
- *
98
- * @return string Submenu markup with the directives injected.
99
- */
100
- function block_core_navigation_add_directives_to_submenu( $w, $block_attributes ) {
101
- while ( $w->next_tag(
71
+ /**
72
+ * Add Interactivity API directives to the navigation-submenu and page-list
73
+ * blocks markup using the Tag Processor.
74
+ *
75
+ * @param string $w Markup of the navigation block.
76
+ * @param array $block_attributes Block attributes.
77
+ *
78
+ * @return string Submenu markup with the directives injected.
79
+ */
80
+ function block_core_navigation_add_directives_to_submenu( $w, $block_attributes ) {
81
+ while ( $w->next_tag(
82
+ array(
83
+ 'tag_name' => 'LI',
84
+ 'class_name' => 'has-child',
85
+ )
86
+ ) ) {
87
+ // Add directives to the parent `<li>`.
88
+ $w->set_attribute( 'data-wp-interactive', true );
89
+ $w->set_attribute( 'data-wp-context', '{ "core": { "navigation": { "submenuOpenedBy": {}, "type": "submenu" } } }' );
90
+ $w->set_attribute( 'data-wp-effect', 'effects.core.navigation.initMenu' );
91
+ $w->set_attribute( 'data-wp-on--focusout', 'actions.core.navigation.handleMenuFocusout' );
92
+ $w->set_attribute( 'data-wp-on--keydown', 'actions.core.navigation.handleMenuKeydown' );
93
+ if ( ! isset( $block_attributes['openSubmenusOnClick'] ) || false === $block_attributes['openSubmenusOnClick'] ) {
94
+ $w->set_attribute( 'data-wp-on--mouseenter', 'actions.core.navigation.openMenuOnHover' );
95
+ $w->set_attribute( 'data-wp-on--mouseleave', 'actions.core.navigation.closeMenuOnHover' );
96
+ }
97
+
98
+ // Add directives to the toggle submenu button.
99
+ if ( $w->next_tag(
102
100
  array(
103
- 'tag_name' => 'LI',
104
- 'class_name' => 'has-child',
101
+ 'tag_name' => 'BUTTON',
102
+ 'class_name' => 'wp-block-navigation-submenu__toggle',
105
103
  )
106
104
  ) ) {
107
- // Add directives to the parent `<li>`.
108
- $w->set_attribute( 'data-wp-interactive', true );
109
- $w->set_attribute( 'data-wp-context', '{ "core": { "navigation": { "submenuOpenedBy": {}, "type": "submenu" } } }' );
110
- $w->set_attribute( 'data-wp-effect', 'effects.core.navigation.initMenu' );
111
- $w->set_attribute( 'data-wp-on--focusout', 'actions.core.navigation.handleMenuFocusout' );
112
- $w->set_attribute( 'data-wp-on--keydown', 'actions.core.navigation.handleMenuKeydown' );
113
- if ( ! isset( $block_attributes['openSubmenusOnClick'] ) || false === $block_attributes['openSubmenusOnClick'] ) {
114
- $w->set_attribute( 'data-wp-on--mouseenter', 'actions.core.navigation.openMenuOnHover' );
115
- $w->set_attribute( 'data-wp-on--mouseleave', 'actions.core.navigation.closeMenuOnHover' );
116
- }
117
-
118
- // Add directives to the toggle submenu button.
119
- if ( $w->next_tag(
120
- array(
121
- 'tag_name' => 'BUTTON',
122
- 'class_name' => 'wp-block-navigation-submenu__toggle',
123
- )
124
- ) ) {
125
- $w->set_attribute( 'data-wp-on--click', 'actions.core.navigation.toggleMenuOnClick' );
126
- $w->set_attribute( 'data-wp-bind--aria-expanded', 'selectors.core.navigation.isMenuOpen' );
127
- };
128
-
129
- // Add directives to the submenu.
130
- if ( $w->next_tag(
131
- array(
132
- 'tag_name' => 'UL',
133
- 'class_name' => 'wp-block-navigation__submenu-container',
134
- )
135
- ) ) {
136
- $w->set_attribute( 'data-wp-on--focusin', 'actions.core.navigation.openMenuOnFocus' );
137
- }
138
-
139
- // Iterate through subitems if exist.
140
- block_core_navigation_add_directives_to_submenu( $w, $block_attributes );
105
+ $w->set_attribute( 'data-wp-on--click', 'actions.core.navigation.toggleMenuOnClick' );
106
+ $w->set_attribute( 'data-wp-bind--aria-expanded', 'selectors.core.navigation.isMenuOpen' );
107
+ // The `aria-expanded` attribute for SSR is already added in the submenu block.
141
108
  }
142
- return $w->get_updated_html();
143
- };
144
-
145
- /**
146
- * Replaces view script for the Navigation block with version using Interactivity API.
147
- *
148
- * @param array $metadata Block metadata as read in via block.json.
149
- *
150
- * @return array Filtered block type metadata.
151
- */
152
- function gutenberg_block_core_navigation_update_interactive_view_script( $metadata ) {
153
- if ( 'core/navigation' === $metadata['name'] ) {
154
- $metadata['viewScript'] = array( 'file:./view-interactivity.min.js' );
155
- $metadata['supports']['interactivity'] = true;
109
+ // Add directives to the submenu.
110
+ if ( $w->next_tag(
111
+ array(
112
+ 'tag_name' => 'UL',
113
+ 'class_name' => 'wp-block-navigation__submenu-container',
114
+ )
115
+ ) ) {
116
+ $w->set_attribute( 'data-wp-on--focus', 'actions.core.navigation.openMenuOnFocus' );
156
117
  }
157
- return $metadata;
118
+
119
+ // Iterate through subitems if exist.
120
+ block_core_navigation_add_directives_to_submenu( $w, $block_attributes );
158
121
  }
159
- add_filter( 'block_type_metadata', 'gutenberg_block_core_navigation_update_interactive_view_script', 10, 1 );
122
+ return $w->get_updated_html();
160
123
  }
161
124
 
162
-
163
125
  /**
164
126
  * Build an array with CSS classes and inline styles defining the colors
165
127
  * which will be applied to the navigation markup in the front-end.
@@ -289,10 +251,6 @@ function block_core_navigation_render_submenu_icon() {
289
251
  return '<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none" aria-hidden="true" focusable="false"><path d="M1.50002 4L6.00002 8L10.5 4" stroke-width="1.5"></path></svg>';
290
252
  }
291
253
 
292
-
293
-
294
-
295
-
296
254
  /**
297
255
  * Filter out empty "null" blocks from the block list.
298
256
  * 'parse_blocks' includes a null block with '\n\n' as the content when
@@ -305,7 +263,7 @@ function block_core_navigation_render_submenu_icon() {
305
263
  function block_core_navigation_filter_out_empty_blocks( $parsed_blocks ) {
306
264
  $filtered = array_filter(
307
265
  $parsed_blocks,
308
- static function( $block ) {
266
+ static function ( $block ) {
309
267
  return isset( $block['blockName'] );
310
268
  }
311
269
  );
@@ -435,7 +393,7 @@ function render_block_core_navigation( $attributes, $content, $block ) {
435
393
  // a fallback (i.e. the block has no menu associated with it).
436
394
  $is_fallback = false;
437
395
 
438
- $nav_menu_name = '';
396
+ $nav_menu_name = $attributes['ariaLabel'] ?? '';
439
397
 
440
398
  /**
441
399
  * Deprecated:
@@ -571,7 +529,7 @@ function render_block_core_navigation( $attributes, $content, $block ) {
571
529
  }
572
530
 
573
531
  // Manually add block support text decoration as CSS class.
574
- $text_decoration = _wp_array_get( $attributes, array( 'style', 'typography', 'textDecoration' ), null );
532
+ $text_decoration = $attributes['style']['typography']['textDecoration'] ?? null;
575
533
  $text_decoration_class = sprintf( 'has-text-decoration-%s', $text_decoration );
576
534
 
577
535
  $colors = block_core_navigation_build_css_colors( $attributes );
@@ -671,38 +629,25 @@ function render_block_core_navigation( $attributes, $content, $block ) {
671
629
  $inner_blocks_html .= '</ul>';
672
630
  }
673
631
 
674
- $needed_script_map = array(
675
- 'wp-block-navigation-view' => ( $has_submenus && ( $attributes['openSubmenusOnClick'] || $attributes['showSubmenuIcon'] ) ),
676
- 'wp-block-navigation-view-2' => $is_responsive_menu,
677
- );
678
-
679
- $should_load_view_script = false;
680
- if ( gutenberg_should_block_use_interactivity_api( 'core/navigation' ) ) {
681
- // TODO: The script is still loaded even when it isn't needed when the Interactivity API is used.
682
- $should_load_view_script = count( array_filter( $needed_script_map ) ) > 0;
683
- } else {
684
- foreach ( $needed_script_map as $view_script_handle => $is_view_script_needed ) {
685
-
686
- // If the script already exists, there is no point in removing it from viewScript.
687
- if ( wp_script_is( $view_script_handle ) ) {
688
- continue;
689
- }
632
+ $should_load_view_script = ( $has_submenus && ( $attributes['openSubmenusOnClick'] || $attributes['showSubmenuIcon'] ) ) || $is_responsive_menu;
633
+ $view_js_file = 'wp-block-navigation-view';
690
634
 
691
- $script_handles = $block->block_type->view_script_handles;
635
+ // If the script already exists, there is no point in removing it from viewScript.
636
+ if ( ! wp_script_is( $view_js_file ) ) {
637
+ $script_handles = $block->block_type->view_script_handles;
692
638
 
693
- // If the script is not needed, and it is still in the `view_script_handles`, remove it.
694
- if ( ! $is_view_script_needed && in_array( $view_script_handle, $script_handles, true ) ) {
695
- $block->block_type->view_script_handles = array_diff( $script_handles, array( $view_script_handle ) );
696
- }
697
- // If the script is needed, but it was previously removed, add it again.
698
- if ( $is_view_script_needed && ! in_array( $view_script_handle, $script_handles, true ) ) {
699
- $block->block_type->view_script_handles = array_merge( $script_handles, array( $view_script_handle ) );
700
- }
639
+ // If the script is not needed, and it is still in the `view_script_handles`, remove it.
640
+ if ( ! $should_load_view_script && in_array( $view_js_file, $script_handles, true ) ) {
641
+ $block->block_type->view_script_handles = array_diff( $script_handles, array( $view_js_file ) );
642
+ }
643
+ // If the script is needed, but it was previously removed, add it again.
644
+ if ( $should_load_view_script && ! in_array( $view_js_file, $script_handles, true ) ) {
645
+ $block->block_type->view_script_handles = array_merge( $script_handles, array( $view_js_file ) );
701
646
  }
702
647
  }
703
648
 
704
649
  // Add directives to the submenu if needed.
705
- if ( gutenberg_should_block_use_interactivity_api( 'core/navigation' ) && $has_submenus && $should_load_view_script ) {
650
+ if ( $has_submenus && $should_load_view_script ) {
706
651
  $w = new WP_HTML_Tag_Processor( $inner_blocks_html );
707
652
  $inner_blocks_html = block_core_navigation_add_directives_to_submenu( $w, $attributes );
708
653
  }
@@ -750,7 +695,7 @@ function render_block_core_navigation( $attributes, $content, $block ) {
750
695
  $responsive_container_directives = '';
751
696
  $responsive_dialog_directives = '';
752
697
  $close_button_directives = '';
753
- if ( gutenberg_should_block_use_interactivity_api( 'core/navigation' ) && $should_load_view_script ) {
698
+ if ( $should_load_view_script ) {
754
699
  $nav_element_directives = '
755
700
  data-wp-interactive
756
701
  data-wp-context=\'{ "core": { "navigation": { "overlayOpenedBy": {}, "type": "overlay", "roleAttribute": "" } } }\'
@@ -768,7 +713,7 @@ function render_block_core_navigation( $attributes, $content, $block ) {
768
713
  tabindex="-1"
769
714
  ';
770
715
  $responsive_dialog_directives = '
771
- data-wp-bind--aria-modal="selectors.core.navigation.isMenuOpen"
716
+ data-wp-bind--aria-modal="selectors.core.navigation.ariaModal"
772
717
  data-wp-bind--role="selectors.core.navigation.roleAttribute"
773
718
  data-wp-effect="effects.core.navigation.focusFirstElement"
774
719
  ';
@@ -778,11 +723,11 @@ function render_block_core_navigation( $attributes, $content, $block ) {
778
723
  }
779
724
 
780
725
  $responsive_container_markup = sprintf(
781
- '<button aria-haspopup="true" %3$s class="%6$s" data-micromodal-trigger="%1$s" %11$s>%9$s</button>
726
+ '<button aria-haspopup="true" %3$s class="%6$s" %11$s>%9$s</button>
782
727
  <div class="%5$s" style="%7$s" id="%1$s" %12$s>
783
- <div class="wp-block-navigation__responsive-close" tabindex="-1" data-micromodal-close>
728
+ <div class="wp-block-navigation__responsive-close" tabindex="-1">
784
729
  <div class="wp-block-navigation__responsive-dialog" aria-label="%8$s" %13$s>
785
- <button %4$s data-micromodal-close class="wp-block-navigation__responsive-container-close" %14$s>%10$s</button>
730
+ <button %4$s class="wp-block-navigation__responsive-container-close" %14$s>%10$s</button>
786
731
  <div class="wp-block-navigation__responsive-container-content" id="%1$s-content">
787
732
  %2$s
788
733
  </div>
@@ -864,6 +809,23 @@ function block_core_navigation_typographic_presets_backcompatibility( $parsed_bl
864
809
 
865
810
  add_filter( 'render_block_data', 'block_core_navigation_typographic_presets_backcompatibility' );
866
811
 
812
+ /**
813
+ * Ensure that the view script has the `wp-interactivity` dependency.
814
+ *
815
+ * @since 6.4.0
816
+ */
817
+ function block_core_navigation_ensure_interactivity_dependency() {
818
+ global $wp_scripts;
819
+ if (
820
+ isset( $wp_scripts->registered['wp-block-navigation-view'] ) &&
821
+ ! in_array( 'wp-interactivity', $wp_scripts->registered['wp-block-navigation-view']->deps, true )
822
+ ) {
823
+ $wp_scripts->registered['wp-block-navigation-view']->deps[] = 'wp-interactivity';
824
+ }
825
+ }
826
+
827
+ add_action( 'wp_print_scripts', 'block_core_navigation_ensure_interactivity_dependency' );
828
+
867
829
  /**
868
830
  * Turns menu item data into a nested array of parsed blocks
869
831
  *
@@ -957,7 +919,7 @@ function block_core_navigation_get_classic_menu_fallback() {
957
919
  // Otherwise return the most recently created classic menu.
958
920
  usort(
959
921
  $classic_nav_menus,
960
- static function( $a, $b ) {
922
+ static function ( $a, $b ) {
961
923
  return $b->term_id - $a->term_id;
962
924
  }
963
925
  );
@@ -1,107 +1,203 @@
1
- /*eslint-env browser*/
2
- // Open on click functionality.
3
-
4
- /**
5
- * Keep track of whether a submenu is open to short-circuit delegated event listeners.
6
- *
7
- * @type {boolean}
8
- */
9
- let hasOpenSubmenu = false;
10
-
11
- /**
12
- * Close submenu items for a navigation item.
13
- *
14
- * @param {HTMLElement} navigationItem - Either a NAV or LI element.
15
- */
16
- function closeSubmenus( navigationItem ) {
17
- navigationItem
18
- .querySelectorAll( '[aria-expanded="true"]' )
19
- .forEach( function ( toggle ) {
20
- toggle.setAttribute( 'aria-expanded', 'false' );
21
- } );
22
- hasOpenSubmenu = false;
23
- }
24
-
25
1
  /**
26
- * Toggle submenu on click.
27
- *
28
- * @param {HTMLButtonElement} buttonToggle
2
+ * WordPress dependencies
29
3
  */
30
- function toggleSubmenuOnClick( buttonToggle ) {
31
- const isSubmenuOpen =
32
- buttonToggle.getAttribute( 'aria-expanded' ) === 'true';
33
- const navigationItem = buttonToggle.closest( '.wp-block-navigation-item' );
4
+ import { store as wpStore } from '@wordpress/interactivity';
34
5
 
35
- if ( isSubmenuOpen ) {
36
- closeSubmenus( navigationItem );
37
- } else {
38
- // Close all sibling submenus.
39
- const navigationParent = buttonToggle.closest(
40
- '.wp-block-navigation__submenu-container, .wp-block-navigation__container, .wp-block-page-list'
41
- );
42
- navigationParent
43
- .querySelectorAll( '.wp-block-navigation-item' )
44
- .forEach( ( child ) => {
45
- if ( child !== navigationItem ) {
46
- closeSubmenus( child );
47
- }
48
- } );
6
+ const focusableSelectors = [
7
+ 'a[href]',
8
+ 'input:not([disabled]):not([type="hidden"]):not([aria-hidden])',
9
+ 'select:not([disabled]):not([aria-hidden])',
10
+ 'textarea:not([disabled]):not([aria-hidden])',
11
+ 'button:not([disabled]):not([aria-hidden])',
12
+ '[contenteditable]',
13
+ '[tabindex]:not([tabindex^="-"])',
14
+ ];
49
15
 
50
- // Open submenu.
51
- buttonToggle.setAttribute( 'aria-expanded', 'true' );
52
- hasOpenSubmenu = true;
16
+ const openMenu = ( store, menuOpenedOn ) => {
17
+ const { context, ref, selectors } = store;
18
+ selectors.core.navigation.menuOpenedBy( store )[ menuOpenedOn ] = true;
19
+ context.core.navigation.previousFocus = ref;
20
+ if ( context.core.navigation.type === 'overlay' ) {
21
+ // Add a `has-modal-open` class to the <html> root.
22
+ document.documentElement.classList.add( 'has-modal-open' );
53
23
  }
54
- }
24
+ };
55
25
 
56
- // Open on button click or close on click outside.
57
- document.addEventListener(
58
- 'click',
59
- function ( event ) {
60
- const target = event.target;
61
- const button = target.closest( '.wp-block-navigation-submenu__toggle' );
62
-
63
- // Close any other open submenus.
64
- if ( hasOpenSubmenu ) {
65
- const navigationBlocks = document.querySelectorAll(
66
- '.wp-block-navigation'
67
- );
68
- navigationBlocks.forEach( function ( block ) {
69
- if ( ! block.contains( target ) ) {
70
- closeSubmenus( block );
71
- }
72
- } );
26
+ const closeMenu = ( store, menuClosedOn ) => {
27
+ const { context, selectors } = store;
28
+ selectors.core.navigation.menuOpenedBy( store )[ menuClosedOn ] = false;
29
+ // Check if the menu is still open or not.
30
+ if ( ! selectors.core.navigation.isMenuOpen( store ) ) {
31
+ if (
32
+ context.core.navigation.modal?.contains(
33
+ window.document.activeElement
34
+ )
35
+ ) {
36
+ context.core.navigation.previousFocus.focus();
73
37
  }
74
-
75
- // Now open the submenu if one was clicked.
76
- if ( button instanceof HTMLButtonElement ) {
77
- toggleSubmenuOnClick( button );
38
+ context.core.navigation.modal = null;
39
+ context.core.navigation.previousFocus = null;
40
+ if ( context.core.navigation.type === 'overlay' ) {
41
+ document.documentElement.classList.remove( 'has-modal-open' );
78
42
  }
79
- },
80
- { passive: true }
81
- );
43
+ }
44
+ };
82
45
 
83
- // Close on focus outside or escape key.
84
- document.addEventListener(
85
- 'keyup',
86
- function ( event ) {
87
- // Abort if there aren't any submenus open anyway.
88
- if ( ! hasOpenSubmenu ) {
89
- return;
90
- }
46
+ wpStore( {
47
+ effects: {
48
+ core: {
49
+ navigation: {
50
+ initMenu: ( store ) => {
51
+ const { context, selectors, ref } = store;
52
+ if ( selectors.core.navigation.isMenuOpen( store ) ) {
53
+ const focusableElements =
54
+ ref.querySelectorAll( focusableSelectors );
55
+ context.core.navigation.modal = ref;
56
+ context.core.navigation.firstFocusableElement =
57
+ focusableElements[ 0 ];
58
+ context.core.navigation.lastFocusableElement =
59
+ focusableElements[ focusableElements.length - 1 ];
60
+ }
61
+ },
62
+ focusFirstElement: ( store ) => {
63
+ const { selectors, ref } = store;
64
+ if ( selectors.core.navigation.isMenuOpen( store ) ) {
65
+ ref.querySelector(
66
+ '.wp-block-navigation-item > *:first-child'
67
+ ).focus();
68
+ }
69
+ },
70
+ },
71
+ },
72
+ },
73
+ selectors: {
74
+ core: {
75
+ navigation: {
76
+ roleAttribute: ( store ) => {
77
+ const { context, selectors } = store;
78
+ return context.core.navigation.type === 'overlay' &&
79
+ selectors.core.navigation.isMenuOpen( store )
80
+ ? 'dialog'
81
+ : null;
82
+ },
83
+ ariaModal: ( store ) => {
84
+ const { context, selectors } = store;
85
+ return context.core.navigation.type === 'overlay' &&
86
+ selectors.core.navigation.isMenuOpen( store )
87
+ ? 'true'
88
+ : null;
89
+ },
90
+ isMenuOpen: ( { context } ) =>
91
+ // The menu is opened if either `click`, `hover` or `focus` is true.
92
+ Object.values(
93
+ context.core.navigation[
94
+ context.core.navigation.type === 'overlay'
95
+ ? 'overlayOpenedBy'
96
+ : 'submenuOpenedBy'
97
+ ]
98
+ ).filter( Boolean ).length > 0,
99
+ menuOpenedBy: ( { context } ) =>
100
+ context.core.navigation[
101
+ context.core.navigation.type === 'overlay'
102
+ ? 'overlayOpenedBy'
103
+ : 'submenuOpenedBy'
104
+ ],
105
+ },
106
+ },
107
+ },
108
+ actions: {
109
+ core: {
110
+ navigation: {
111
+ openMenuOnHover( store ) {
112
+ const { navigation } = store.context.core;
113
+ if (
114
+ navigation.type === 'submenu' &&
115
+ // Only open on hover if the overlay is closed.
116
+ Object.values(
117
+ navigation.overlayOpenedBy || {}
118
+ ).filter( Boolean ).length === 0
119
+ )
120
+ openMenu( store, 'hover' );
121
+ },
122
+ closeMenuOnHover( store ) {
123
+ closeMenu( store, 'hover' );
124
+ },
125
+ openMenuOnClick( store ) {
126
+ openMenu( store, 'click' );
127
+ },
128
+ closeMenuOnClick( store ) {
129
+ closeMenu( store, 'click' );
130
+ closeMenu( store, 'focus' );
131
+ },
132
+ openMenuOnFocus( store ) {
133
+ openMenu( store, 'focus' );
134
+ },
135
+ toggleMenuOnClick: ( store ) => {
136
+ const { selectors } = store;
137
+ const menuOpenedBy =
138
+ selectors.core.navigation.menuOpenedBy( store );
139
+ if ( menuOpenedBy.click || menuOpenedBy.focus ) {
140
+ closeMenu( store, 'click' );
141
+ closeMenu( store, 'focus' );
142
+ } else {
143
+ openMenu( store, 'click' );
144
+ }
145
+ },
146
+ handleMenuKeydown: ( store ) => {
147
+ const { context, selectors, event } = store;
148
+ if (
149
+ selectors.core.navigation.menuOpenedBy( store ).click
150
+ ) {
151
+ // If Escape close the menu.
152
+ if ( event?.key === 'Escape' ) {
153
+ closeMenu( store, 'click' );
154
+ closeMenu( store, 'focus' );
155
+ return;
156
+ }
91
157
 
92
- const submenuBlocks = document.querySelectorAll(
93
- '.wp-block-navigation-item.has-child'
94
- );
95
- submenuBlocks.forEach( function ( block ) {
96
- if ( ! block.contains( event.target ) ) {
97
- closeSubmenus( block );
98
- } else if ( event.key === 'Escape' ) {
99
- const toggle = block.querySelector( '[aria-expanded="true"]' );
100
- closeSubmenus( block );
101
- // Focus the submenu trigger so focus does not get trapped in the closed submenu.
102
- toggle?.focus();
103
- }
104
- } );
158
+ // Trap focus if it is an overlay (main menu).
159
+ if (
160
+ context.core.navigation.type === 'overlay' &&
161
+ event.key === 'Tab'
162
+ ) {
163
+ // If shift + tab it change the direction.
164
+ if (
165
+ event.shiftKey &&
166
+ window.document.activeElement ===
167
+ context.core.navigation
168
+ .firstFocusableElement
169
+ ) {
170
+ event.preventDefault();
171
+ context.core.navigation.lastFocusableElement.focus();
172
+ } else if (
173
+ ! event.shiftKey &&
174
+ window.document.activeElement ===
175
+ context.core.navigation.lastFocusableElement
176
+ ) {
177
+ event.preventDefault();
178
+ context.core.navigation.firstFocusableElement.focus();
179
+ }
180
+ }
181
+ }
182
+ },
183
+ handleMenuFocusout: ( store ) => {
184
+ const { context, event } = store;
185
+ // If focus is outside modal, and in the document, close menu
186
+ // event.target === The element losing focus
187
+ // event.relatedTarget === The element receiving focus (if any)
188
+ // When focusout is outsite the document,
189
+ // `window.document.activeElement` doesn't change.
190
+ if (
191
+ ! context.core.navigation.modal?.contains(
192
+ event.relatedTarget
193
+ ) &&
194
+ event.target !== window.document.activeElement
195
+ ) {
196
+ closeMenu( store, 'click' );
197
+ closeMenu( store, 'focus' );
198
+ }
199
+ },
200
+ },
201
+ },
105
202
  },
106
- { passive: true }
107
- );
203
+ } );