@wordpress/block-library 7.3.10 → 7.6.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 (752) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +3 -2
  3. package/babel-plugin.js +154 -0
  4. package/build/archives/edit.js +1 -1
  5. package/build/archives/edit.js.map +1 -1
  6. package/build/audio/edit.js +5 -17
  7. package/build/audio/edit.js.map +1 -1
  8. package/build/audio/edit.native.js +1 -1
  9. package/build/audio/edit.native.js.map +1 -1
  10. package/build/block/edit.js +10 -9
  11. package/build/block/edit.js.map +1 -1
  12. package/build/button/edit.native.js +7 -3
  13. package/build/button/edit.native.js.map +1 -1
  14. package/build/button/index.js +1 -0
  15. package/build/button/index.js.map +1 -1
  16. package/build/categories/edit.js +9 -4
  17. package/build/categories/edit.js.map +1 -1
  18. package/build/categories/index.js +5 -1
  19. package/build/categories/index.js.map +1 -1
  20. package/build/column/index.js +10 -0
  21. package/build/column/index.js.map +1 -1
  22. package/build/comment-author-avatar/index.js +1 -0
  23. package/build/comment-author-avatar/index.js.map +1 -1
  24. package/build/comment-template/edit.js +1 -3
  25. package/build/comment-template/edit.js.map +1 -1
  26. package/build/{comments-query-loop → comments}/edit/comments-inspector-controls.js +0 -0
  27. package/{build-module/comments-query-loop → build/comments}/edit/comments-inspector-controls.js.map +1 -1
  28. package/build/{comments-query-loop → comments}/edit.js +2 -2
  29. package/build/comments/edit.js.map +1 -0
  30. package/build/{comments-query-loop → comments}/index.js +1 -1
  31. package/build/comments/index.js.map +1 -0
  32. package/build/{comments-query-loop → comments}/save.js +2 -2
  33. package/build/comments/save.js.map +1 -0
  34. package/build/comments-title/index.js +1 -1
  35. package/build/comments-title/index.js.map +1 -1
  36. package/build/cover/controls.native.js +2 -3
  37. package/build/cover/controls.native.js.map +1 -1
  38. package/build/cover/edit/block-controls.js +115 -0
  39. package/build/cover/edit/block-controls.js.map +1 -0
  40. package/build/cover/edit/cover-placeholder.js +49 -0
  41. package/build/cover/edit/cover-placeholder.js.map +1 -0
  42. package/build/cover/edit/index.js +333 -0
  43. package/build/cover/edit/index.js.map +1 -0
  44. package/build/cover/edit/inspector-controls.js +224 -0
  45. package/build/cover/edit/inspector-controls.js.map +1 -0
  46. package/build/cover/edit/resizable-cover.js +67 -0
  47. package/build/cover/edit/resizable-cover.js.map +1 -0
  48. package/build/cover/edit/use-cover-is-dark.js +81 -0
  49. package/build/cover/edit/use-cover-is-dark.js.map +1 -0
  50. package/build/cover/edit.native.js +36 -16
  51. package/build/cover/edit.native.js.map +1 -1
  52. package/build/cover/focal-point-settings-button.native.js.map +1 -1
  53. package/build/cover/shared.js +9 -0
  54. package/build/cover/shared.js.map +1 -1
  55. package/build/cover/transforms.js +77 -6
  56. package/build/cover/transforms.js.map +1 -1
  57. package/build/cover/use-cover-is-dark.native.js +60 -0
  58. package/build/cover/use-cover-is-dark.native.js.map +1 -0
  59. package/build/embed/edit.js +12 -18
  60. package/build/embed/edit.js.map +1 -1
  61. package/build/embed/edit.native.js +1 -7
  62. package/build/embed/edit.native.js.map +1 -1
  63. package/build/embed/embed-preview.js +1 -1
  64. package/build/embed/embed-preview.js.map +1 -1
  65. package/build/embed/util.js +29 -4
  66. package/build/embed/util.js.map +1 -1
  67. package/build/file/edit.native.js +0 -1
  68. package/build/file/edit.native.js.map +1 -1
  69. package/build/file/inspector.js +2 -4
  70. package/build/file/inspector.js.map +1 -1
  71. package/build/gallery/edit.js +3 -2
  72. package/build/gallery/edit.js.map +1 -1
  73. package/build/gallery/gallery.js +1 -1
  74. package/build/gallery/gallery.js.map +1 -1
  75. package/build/gallery/shared.js +2 -2
  76. package/build/gallery/shared.js.map +1 -1
  77. package/build/gallery/use-get-media.js +2 -1
  78. package/build/gallery/use-get-media.js.map +1 -1
  79. package/build/gallery/use-short-code-transform.js +19 -18
  80. package/build/gallery/use-short-code-transform.js.map +1 -1
  81. package/build/gallery/v1/edit.js +1 -1
  82. package/build/gallery/v1/edit.js.map +1 -1
  83. package/build/gallery/v1/gallery.js +1 -1
  84. package/build/gallery/v1/gallery.js.map +1 -1
  85. package/build/group/index.js +1 -0
  86. package/build/group/index.js.map +1 -1
  87. package/build/heading/edit.js +6 -2
  88. package/build/heading/edit.js.map +1 -1
  89. package/build/heading/index.js +1 -0
  90. package/build/heading/index.js.map +1 -1
  91. package/build/heading/transforms.js +9 -4
  92. package/build/heading/transforms.js.map +1 -1
  93. package/build/html/edit.js +2 -2
  94. package/build/html/edit.js.map +1 -1
  95. package/build/image/edit.js +9 -8
  96. package/build/image/edit.js.map +1 -1
  97. package/build/image/edit.native.js +1 -2
  98. package/build/image/edit.native.js.map +1 -1
  99. package/build/image/image.js +2 -2
  100. package/build/image/image.js.map +1 -1
  101. package/build/index.js +48 -12
  102. package/build/index.js.map +1 -1
  103. package/build/index.native.js +14 -3
  104. package/build/index.native.js.map +1 -1
  105. package/build/is-block-metadata-experimental.js +18 -0
  106. package/build/is-block-metadata-experimental.js.map +1 -0
  107. package/build/latest-comments/edit.js +1 -1
  108. package/build/latest-comments/edit.js.map +1 -1
  109. package/build/latest-posts/edit.js +30 -4
  110. package/build/latest-posts/edit.js.map +1 -1
  111. package/build/latest-posts/edit.native.js +49 -0
  112. package/build/latest-posts/edit.native.js.map +1 -1
  113. package/build/list/transforms.js +6 -0
  114. package/build/list/transforms.js.map +1 -1
  115. package/build/list/v2/edit.js +2 -1
  116. package/build/list/v2/edit.js.map +1 -1
  117. package/build/list/v2/migrate.js +1 -0
  118. package/build/list/v2/migrate.js.map +1 -1
  119. package/build/list/v2/transforms.js +46 -9
  120. package/build/list/v2/transforms.js.map +1 -1
  121. package/build/list-item/edit.js +7 -9
  122. package/build/list-item/edit.js.map +1 -1
  123. package/build/list-item/hooks/index.js +24 -0
  124. package/build/list-item/hooks/index.js.map +1 -1
  125. package/build/list-item/hooks/use-backspace.js +59 -0
  126. package/build/list-item/hooks/use-backspace.js.map +1 -0
  127. package/build/list-item/hooks/use-enter.js +6 -9
  128. package/build/list-item/hooks/use-enter.js.map +1 -1
  129. package/build/list-item/hooks/use-indent-list-item.js +33 -39
  130. package/build/list-item/hooks/use-indent-list-item.js.map +1 -1
  131. package/build/list-item/hooks/use-space.js +54 -0
  132. package/build/list-item/hooks/use-space.js.map +1 -0
  133. package/build/list-item/hooks/use-split.js +30 -0
  134. package/build/list-item/hooks/use-split.js.map +1 -0
  135. package/build/list-item/index.js +1 -0
  136. package/build/list-item/index.js.map +1 -1
  137. package/build/list-item/utils.js +1 -1
  138. package/build/list-item/utils.js.map +1 -1
  139. package/build/loginout/edit.js +1 -1
  140. package/build/loginout/edit.js.map +1 -1
  141. package/build/media-text/edit.js +1 -2
  142. package/build/media-text/edit.js.map +1 -1
  143. package/build/media-text/edit.native.js +3 -2
  144. package/build/media-text/edit.native.js.map +1 -1
  145. package/build/media-text/media-container.native.js +2 -4
  146. package/build/media-text/media-container.native.js.map +1 -1
  147. package/build/media-text/transforms.js +137 -8
  148. package/build/media-text/transforms.js.map +1 -1
  149. package/build/navigation/edit/index.js +86 -81
  150. package/build/navigation/edit/index.js.map +1 -1
  151. package/build/navigation/edit/inner-blocks.js +1 -5
  152. package/build/navigation/edit/inner-blocks.js.map +1 -1
  153. package/build/navigation/edit/unsaved-inner-blocks.js +5 -4
  154. package/build/navigation/edit/unsaved-inner-blocks.js.map +1 -1
  155. package/build/navigation/index.js +1 -1
  156. package/build/navigation/use-navigation-entities.js +3 -3
  157. package/build/navigation/use-navigation-entities.js.map +1 -1
  158. package/build/navigation/view-modal.js +62 -0
  159. package/build/navigation/view-modal.js.map +1 -0
  160. package/build/navigation/view.js +1 -34
  161. package/build/navigation/view.js.map +1 -1
  162. package/build/navigation-link/edit.js +1 -1
  163. package/build/navigation-link/edit.js.map +1 -1
  164. package/build/navigation-link/fallback-variations.js +1 -1
  165. package/build/navigation-link/fallback-variations.js.map +1 -1
  166. package/build/navigation-link/hooks.js +1 -1
  167. package/build/navigation-link/hooks.js.map +1 -1
  168. package/build/page-list/convert-to-links-modal.js +1 -1
  169. package/build/page-list/convert-to-links-modal.js.map +1 -1
  170. package/build/page-list/edit.js +1 -1
  171. package/build/page-list/edit.js.map +1 -1
  172. package/build/paragraph/edit.js +10 -0
  173. package/build/paragraph/edit.js.map +1 -1
  174. package/build/paragraph/edit.native.js +6 -2
  175. package/build/paragraph/edit.native.js.map +1 -1
  176. package/build/paragraph/use-enter.js +94 -0
  177. package/build/paragraph/use-enter.js.map +1 -0
  178. package/build/post-author/edit.js +2 -2
  179. package/build/post-author/edit.js.map +1 -1
  180. package/build/post-author-name/index.js +1 -0
  181. package/build/post-author-name/index.js.map +1 -1
  182. package/build/post-comment/index.js +2 -1
  183. package/build/post-comment/index.js.map +1 -1
  184. package/build/post-comments/edit.js +14 -35
  185. package/build/post-comments/edit.js.map +1 -1
  186. package/build/post-comments/index.js +1 -1
  187. package/build/post-comments-count/index.js +1 -0
  188. package/build/post-comments-count/index.js.map +1 -1
  189. package/build/post-comments-form/edit.js +37 -24
  190. package/build/post-comments-form/edit.js.map +1 -1
  191. package/build/post-comments-form/form.js +48 -0
  192. package/build/post-comments-form/form.js.map +1 -0
  193. package/build/post-comments-link/index.js +1 -0
  194. package/build/post-comments-link/index.js.map +1 -1
  195. package/build/post-excerpt/edit.js +1 -1
  196. package/build/post-excerpt/edit.js.map +1 -1
  197. package/build/post-featured-image/edit.js +1 -1
  198. package/build/post-featured-image/edit.js.map +1 -1
  199. package/build/post-template/edit.js +7 -2
  200. package/build/post-template/edit.js.map +1 -1
  201. package/build/post-terms/edit.js +35 -4
  202. package/build/post-terms/edit.js.map +1 -1
  203. package/build/post-terms/hooks.js +33 -0
  204. package/build/post-terms/hooks.js.map +1 -0
  205. package/build/post-terms/index.js +20 -5
  206. package/build/post-terms/index.js.map +1 -1
  207. package/build/post-title/index.js +1 -1
  208. package/build/post-title/index.js.map +1 -1
  209. package/build/pullquote/edit.js +1 -1
  210. package/build/pullquote/edit.js.map +1 -1
  211. package/build/pullquote/edit.native.js +1 -1
  212. package/build/pullquote/edit.native.js.map +1 -1
  213. package/build/query/edit/inspector-controls/index.js +26 -17
  214. package/build/query/edit/inspector-controls/index.js.map +1 -1
  215. package/build/query/edit/inspector-controls/parent-control.js +148 -0
  216. package/build/query/edit/inspector-controls/parent-control.js.map +1 -0
  217. package/build/query/edit/inspector-controls/sticky-control.js +41 -0
  218. package/build/query/edit/inspector-controls/sticky-control.js.map +1 -0
  219. package/build/query/index.js +2 -1
  220. package/build/query/index.js.map +1 -1
  221. package/build/query/utils.js +28 -2
  222. package/build/query/utils.js.map +1 -1
  223. package/build/query-title/index.js +1 -1
  224. package/build/query-title/index.js.map +1 -1
  225. package/build/query-title/variations.js +1 -1
  226. package/build/query-title/variations.js.map +1 -1
  227. package/build/quote/edit.js +3 -2
  228. package/build/quote/edit.js.map +1 -1
  229. package/build/quote/index.js +7 -0
  230. package/build/quote/index.js.map +1 -1
  231. package/build/quote/v2/edit.js +12 -4
  232. package/build/quote/v2/edit.js.map +1 -1
  233. package/build/rss/edit.js +1 -1
  234. package/build/rss/edit.js.map +1 -1
  235. package/build/search/edit.js +12 -9
  236. package/build/search/edit.js.map +1 -1
  237. package/build/separator/index.js +3 -0
  238. package/build/separator/index.js.map +1 -1
  239. package/build/site-logo/edit.js +1 -1
  240. package/build/site-logo/edit.js.map +1 -1
  241. package/build/spacer/constants.js +9 -0
  242. package/build/spacer/constants.js.map +1 -0
  243. package/build/spacer/controls.js +3 -3
  244. package/build/spacer/controls.js.map +1 -1
  245. package/build/spacer/controls.native.js +2 -2
  246. package/build/spacer/controls.native.js.map +1 -1
  247. package/build/spacer/edit.js +5 -6
  248. package/build/spacer/edit.js.map +1 -1
  249. package/build/table/edit.js +23 -4
  250. package/build/table/edit.js.map +1 -1
  251. package/build/table-of-contents/edit.js +138 -66
  252. package/build/table-of-contents/edit.js.map +1 -1
  253. package/build/table-of-contents/index.js +13 -3
  254. package/build/table-of-contents/index.js.map +1 -1
  255. package/build/table-of-contents/list.js +16 -9
  256. package/build/table-of-contents/list.js.map +1 -1
  257. package/build/table-of-contents/save.js +40 -0
  258. package/build/table-of-contents/save.js.map +1 -0
  259. package/build/table-of-contents/utils.js +11 -77
  260. package/build/table-of-contents/utils.js.map +1 -1
  261. package/build/tag-cloud/edit.js +1 -1
  262. package/build/tag-cloud/edit.js.map +1 -1
  263. package/build/template-part/edit/index.js +7 -3
  264. package/build/template-part/edit/index.js.map +1 -1
  265. package/build/template-part/edit/inner-blocks.js +3 -8
  266. package/build/template-part/edit/inner-blocks.js.map +1 -1
  267. package/build/video/edit.js +5 -9
  268. package/build/video/edit.js.map +1 -1
  269. package/build/video/edit.native.js +1 -1
  270. package/build/video/edit.native.js.map +1 -1
  271. package/build-module/archives/edit.js +1 -1
  272. package/build-module/archives/edit.js.map +1 -1
  273. package/build-module/audio/edit.js +6 -18
  274. package/build-module/audio/edit.js.map +1 -1
  275. package/build-module/audio/edit.native.js +1 -1
  276. package/build-module/audio/edit.native.js.map +1 -1
  277. package/build-module/block/edit.js +11 -10
  278. package/build-module/block/edit.js.map +1 -1
  279. package/build-module/button/edit.native.js +7 -3
  280. package/build-module/button/edit.native.js.map +1 -1
  281. package/build-module/button/index.js +1 -0
  282. package/build-module/button/index.js.map +1 -1
  283. package/build-module/categories/edit.js +9 -4
  284. package/build-module/categories/edit.js.map +1 -1
  285. package/build-module/categories/index.js +5 -1
  286. package/build-module/categories/index.js.map +1 -1
  287. package/build-module/column/index.js +10 -0
  288. package/build-module/column/index.js.map +1 -1
  289. package/build-module/comment-author-avatar/index.js +1 -0
  290. package/build-module/comment-author-avatar/index.js.map +1 -1
  291. package/build-module/comment-template/edit.js +1 -3
  292. package/build-module/comment-template/edit.js.map +1 -1
  293. package/build-module/{comments-query-loop → comments}/edit/comments-inspector-controls.js +0 -0
  294. package/build-module/comments/edit/comments-inspector-controls.js.map +1 -0
  295. package/build-module/{comments-query-loop → comments}/edit.js +1 -1
  296. package/build-module/comments/edit.js.map +1 -0
  297. package/build-module/{comments-query-loop → comments}/index.js +1 -1
  298. package/build-module/comments/index.js.map +1 -0
  299. package/build-module/{comments-query-loop → comments}/save.js +1 -1
  300. package/build-module/comments/save.js.map +1 -0
  301. package/build-module/comments-title/index.js +1 -1
  302. package/build-module/comments-title/index.js.map +1 -1
  303. package/build-module/cover/controls.native.js +2 -3
  304. package/build-module/cover/controls.native.js.map +1 -1
  305. package/build-module/cover/edit/block-controls.js +104 -0
  306. package/build-module/cover/edit/block-controls.js.map +1 -0
  307. package/build-module/cover/edit/cover-placeholder.js +38 -0
  308. package/build-module/cover/edit/cover-placeholder.js.map +1 -0
  309. package/build-module/cover/edit/index.js +307 -0
  310. package/build-module/cover/edit/index.js.map +1 -0
  311. package/build-module/cover/edit/inspector-controls.js +215 -0
  312. package/build-module/cover/edit/inspector-controls.js.map +1 -0
  313. package/build-module/cover/edit/resizable-cover.js +55 -0
  314. package/build-module/cover/edit/resizable-cover.js.map +1 -0
  315. package/build-module/cover/edit/use-cover-is-dark.js +70 -0
  316. package/build-module/cover/edit/use-cover-is-dark.js.map +1 -0
  317. package/build-module/cover/edit.native.js +35 -17
  318. package/build-module/cover/edit.native.js.map +1 -1
  319. package/build-module/cover/focal-point-settings-button.native.js.map +1 -1
  320. package/build-module/cover/shared.js +7 -0
  321. package/build-module/cover/shared.js.map +1 -1
  322. package/build-module/cover/transforms.js +74 -6
  323. package/build-module/cover/transforms.js.map +1 -1
  324. package/build-module/cover/use-cover-is-dark.native.js +51 -0
  325. package/build-module/cover/use-cover-is-dark.native.js.map +1 -0
  326. package/build-module/embed/edit.js +13 -19
  327. package/build-module/embed/edit.js.map +1 -1
  328. package/build-module/embed/edit.native.js +2 -8
  329. package/build-module/embed/edit.native.js.map +1 -1
  330. package/build-module/embed/embed-preview.js +2 -2
  331. package/build-module/embed/embed-preview.js.map +1 -1
  332. package/build-module/embed/util.js +25 -3
  333. package/build-module/embed/util.js.map +1 -1
  334. package/build-module/file/edit.native.js +0 -1
  335. package/build-module/file/edit.native.js.map +1 -1
  336. package/build-module/file/inspector.js +2 -4
  337. package/build-module/file/inspector.js.map +1 -1
  338. package/build-module/gallery/edit.js +3 -2
  339. package/build-module/gallery/edit.js.map +1 -1
  340. package/build-module/gallery/gallery.js +2 -2
  341. package/build-module/gallery/gallery.js.map +1 -1
  342. package/build-module/gallery/shared.js +2 -2
  343. package/build-module/gallery/shared.js.map +1 -1
  344. package/build-module/gallery/use-get-media.js +2 -1
  345. package/build-module/gallery/use-get-media.js.map +1 -1
  346. package/build-module/gallery/use-short-code-transform.js +19 -18
  347. package/build-module/gallery/use-short-code-transform.js.map +1 -1
  348. package/build-module/gallery/v1/edit.js +1 -1
  349. package/build-module/gallery/v1/edit.js.map +1 -1
  350. package/build-module/gallery/v1/gallery.js +2 -2
  351. package/build-module/gallery/v1/gallery.js.map +1 -1
  352. package/build-module/group/index.js +1 -0
  353. package/build-module/group/index.js.map +1 -1
  354. package/build-module/heading/edit.js +6 -2
  355. package/build-module/heading/edit.js.map +1 -1
  356. package/build-module/heading/index.js +1 -0
  357. package/build-module/heading/index.js.map +1 -1
  358. package/build-module/heading/transforms.js +9 -4
  359. package/build-module/heading/transforms.js.map +1 -1
  360. package/build-module/html/edit.js +2 -2
  361. package/build-module/html/edit.js.map +1 -1
  362. package/build-module/image/edit.js +10 -9
  363. package/build-module/image/edit.js.map +1 -1
  364. package/build-module/image/edit.native.js +1 -2
  365. package/build-module/image/edit.native.js.map +1 -1
  366. package/build-module/image/image.js +3 -3
  367. package/build-module/image/image.js.map +1 -1
  368. package/build-module/index.js +43 -11
  369. package/build-module/index.js.map +1 -1
  370. package/build-module/index.native.js +14 -3
  371. package/build-module/index.native.js.map +1 -1
  372. package/build-module/is-block-metadata-experimental.js +16 -0
  373. package/build-module/is-block-metadata-experimental.js.map +1 -0
  374. package/build-module/latest-comments/edit.js +1 -1
  375. package/build-module/latest-comments/edit.js.map +1 -1
  376. package/build-module/latest-posts/edit.js +29 -5
  377. package/build-module/latest-posts/edit.js.map +1 -1
  378. package/build-module/latest-posts/edit.native.js +51 -2
  379. package/build-module/latest-posts/edit.native.js.map +1 -1
  380. package/build-module/list/transforms.js +6 -0
  381. package/build-module/list/transforms.js.map +1 -1
  382. package/build-module/list/v2/edit.js +2 -1
  383. package/build-module/list/v2/edit.js.map +1 -1
  384. package/build-module/list/v2/migrate.js +1 -3
  385. package/build-module/list/v2/migrate.js.map +1 -1
  386. package/build-module/list/v2/transforms.js +46 -9
  387. package/build-module/list/v2/transforms.js.map +1 -1
  388. package/build-module/list-item/edit.js +8 -9
  389. package/build-module/list-item/edit.js.map +1 -1
  390. package/build-module/list-item/hooks/index.js +3 -0
  391. package/build-module/list-item/hooks/index.js.map +1 -1
  392. package/build-module/list-item/hooks/use-backspace.js +44 -0
  393. package/build-module/list-item/hooks/use-backspace.js.map +1 -0
  394. package/build-module/list-item/hooks/use-enter.js +6 -9
  395. package/build-module/list-item/hooks/use-enter.js.map +1 -1
  396. package/build-module/list-item/hooks/use-indent-list-item.js +33 -38
  397. package/build-module/list-item/hooks/use-indent-list-item.js.map +1 -1
  398. package/build-module/list-item/hooks/use-space.js +40 -0
  399. package/build-module/list-item/hooks/use-space.js.map +1 -0
  400. package/build-module/list-item/hooks/use-split.js +19 -0
  401. package/build-module/list-item/hooks/use-split.js.map +1 -0
  402. package/build-module/list-item/index.js +1 -0
  403. package/build-module/list-item/index.js.map +1 -1
  404. package/build-module/list-item/utils.js +1 -1
  405. package/build-module/list-item/utils.js.map +1 -1
  406. package/build-module/loginout/edit.js +1 -1
  407. package/build-module/loginout/edit.js.map +1 -1
  408. package/build-module/media-text/edit.js +1 -2
  409. package/build-module/media-text/edit.js.map +1 -1
  410. package/build-module/media-text/edit.native.js +3 -2
  411. package/build-module/media-text/edit.native.js.map +1 -1
  412. package/build-module/media-text/media-container.native.js +2 -4
  413. package/build-module/media-text/media-container.native.js.map +1 -1
  414. package/build-module/media-text/transforms.js +137 -8
  415. package/build-module/media-text/transforms.js.map +1 -1
  416. package/build-module/navigation/edit/index.js +87 -82
  417. package/build-module/navigation/edit/index.js.map +1 -1
  418. package/build-module/navigation/edit/inner-blocks.js +2 -6
  419. package/build-module/navigation/edit/inner-blocks.js.map +1 -1
  420. package/build-module/navigation/edit/unsaved-inner-blocks.js +5 -4
  421. package/build-module/navigation/edit/unsaved-inner-blocks.js.map +1 -1
  422. package/build-module/navigation/index.js +1 -1
  423. package/build-module/navigation/use-navigation-entities.js +1 -1
  424. package/build-module/navigation/use-navigation-entities.js.map +1 -1
  425. package/build-module/navigation/view-modal.js +56 -0
  426. package/build-module/navigation/view-modal.js.map +1 -0
  427. package/build-module/navigation/view.js +1 -30
  428. package/build-module/navigation/view.js.map +1 -1
  429. package/build-module/navigation-link/edit.js +1 -1
  430. package/build-module/navigation-link/edit.js.map +1 -1
  431. package/build-module/navigation-link/fallback-variations.js +1 -1
  432. package/build-module/navigation-link/fallback-variations.js.map +1 -1
  433. package/build-module/navigation-link/hooks.js +2 -2
  434. package/build-module/navigation-link/hooks.js.map +1 -1
  435. package/build-module/page-list/convert-to-links-modal.js +1 -1
  436. package/build-module/page-list/convert-to-links-modal.js.map +1 -1
  437. package/build-module/page-list/edit.js +1 -1
  438. package/build-module/page-list/edit.js.map +1 -1
  439. package/build-module/paragraph/edit.js +9 -0
  440. package/build-module/paragraph/edit.js.map +1 -1
  441. package/build-module/paragraph/edit.native.js +6 -2
  442. package/build-module/paragraph/edit.native.js.map +1 -1
  443. package/build-module/paragraph/use-enter.js +81 -0
  444. package/build-module/paragraph/use-enter.js.map +1 -0
  445. package/build-module/post-author/edit.js +2 -2
  446. package/build-module/post-author/edit.js.map +1 -1
  447. package/build-module/post-author-name/index.js +1 -0
  448. package/build-module/post-author-name/index.js.map +1 -1
  449. package/build-module/post-comment/index.js +2 -1
  450. package/build-module/post-comment/index.js.map +1 -1
  451. package/build-module/post-comments/edit.js +13 -35
  452. package/build-module/post-comments/edit.js.map +1 -1
  453. package/build-module/post-comments/index.js +1 -1
  454. package/build-module/post-comments-count/index.js +1 -0
  455. package/build-module/post-comments-count/index.js.map +1 -1
  456. package/build-module/post-comments-form/edit.js +38 -26
  457. package/build-module/post-comments-form/edit.js.map +1 -1
  458. package/build-module/post-comments-form/form.js +39 -0
  459. package/build-module/post-comments-form/form.js.map +1 -0
  460. package/build-module/post-comments-link/index.js +1 -0
  461. package/build-module/post-comments-link/index.js.map +1 -1
  462. package/build-module/post-excerpt/edit.js +1 -1
  463. package/build-module/post-excerpt/edit.js.map +1 -1
  464. package/build-module/post-featured-image/edit.js +1 -1
  465. package/build-module/post-featured-image/edit.js.map +1 -1
  466. package/build-module/post-template/edit.js +7 -2
  467. package/build-module/post-template/edit.js.map +1 -1
  468. package/build-module/post-terms/edit.js +35 -6
  469. package/build-module/post-terms/edit.js.map +1 -1
  470. package/build-module/post-terms/hooks.js +25 -0
  471. package/build-module/post-terms/hooks.js.map +1 -0
  472. package/build-module/post-terms/index.js +18 -8
  473. package/build-module/post-terms/index.js.map +1 -1
  474. package/build-module/post-title/index.js +1 -1
  475. package/build-module/post-title/index.js.map +1 -1
  476. package/build-module/pullquote/edit.js +2 -2
  477. package/build-module/pullquote/edit.js.map +1 -1
  478. package/build-module/pullquote/edit.native.js +2 -2
  479. package/build-module/pullquote/edit.native.js.map +1 -1
  480. package/build-module/query/edit/inspector-controls/index.js +24 -17
  481. package/build-module/query/edit/inspector-controls/index.js.map +1 -1
  482. package/build-module/query/edit/inspector-controls/parent-control.js +135 -0
  483. package/build-module/query/edit/inspector-controls/parent-control.js.map +1 -0
  484. package/build-module/query/edit/inspector-controls/sticky-control.js +31 -0
  485. package/build-module/query/edit/inspector-controls/sticky-control.js.map +1 -0
  486. package/build-module/query/index.js +2 -1
  487. package/build-module/query/index.js.map +1 -1
  488. package/build-module/query/utils.js +21 -0
  489. package/build-module/query/utils.js.map +1 -1
  490. package/build-module/query-title/index.js +1 -1
  491. package/build-module/query-title/index.js.map +1 -1
  492. package/build-module/query-title/variations.js +2 -2
  493. package/build-module/query-title/variations.js.map +1 -1
  494. package/build-module/quote/edit.js +4 -3
  495. package/build-module/quote/edit.js.map +1 -1
  496. package/build-module/quote/index.js +2 -1
  497. package/build-module/quote/index.js.map +1 -1
  498. package/build-module/quote/v2/edit.js +12 -5
  499. package/build-module/quote/v2/edit.js.map +1 -1
  500. package/build-module/rss/edit.js +1 -1
  501. package/build-module/rss/edit.js.map +1 -1
  502. package/build-module/search/edit.js +12 -9
  503. package/build-module/search/edit.js.map +1 -1
  504. package/build-module/separator/index.js +3 -0
  505. package/build-module/separator/index.js.map +1 -1
  506. package/build-module/site-logo/edit.js +1 -1
  507. package/build-module/site-logo/edit.js.map +1 -1
  508. package/build-module/spacer/constants.js +2 -0
  509. package/build-module/spacer/constants.js.map +1 -0
  510. package/build-module/spacer/controls.js +2 -2
  511. package/build-module/spacer/controls.js.map +1 -1
  512. package/build-module/spacer/controls.native.js +1 -1
  513. package/build-module/spacer/controls.native.js.map +1 -1
  514. package/build-module/spacer/edit.js +1 -1
  515. package/build-module/spacer/edit.js.map +1 -1
  516. package/build-module/table/edit.js +26 -7
  517. package/build-module/table/edit.js.map +1 -1
  518. package/build-module/table-of-contents/edit.js +136 -68
  519. package/build-module/table-of-contents/edit.js.map +1 -1
  520. package/build-module/table-of-contents/index.js +12 -3
  521. package/build-module/table-of-contents/index.js.map +1 -1
  522. package/build-module/table-of-contents/list.js +18 -10
  523. package/build-module/table-of-contents/list.js.map +1 -1
  524. package/build-module/table-of-contents/save.js +28 -0
  525. package/build-module/table-of-contents/save.js.map +1 -0
  526. package/build-module/table-of-contents/utils.js +11 -73
  527. package/build-module/table-of-contents/utils.js.map +1 -1
  528. package/build-module/tag-cloud/edit.js +1 -1
  529. package/build-module/tag-cloud/edit.js.map +1 -1
  530. package/build-module/template-part/edit/index.js +8 -4
  531. package/build-module/template-part/edit/index.js.map +1 -1
  532. package/build-module/template-part/edit/inner-blocks.js +4 -9
  533. package/build-module/template-part/edit/inner-blocks.js.map +1 -1
  534. package/build-module/video/edit.js +6 -10
  535. package/build-module/video/edit.js.map +1 -1
  536. package/build-module/video/edit.native.js +1 -1
  537. package/build-module/video/edit.native.js.map +1 -1
  538. package/build-style/{comments-query-loop → comments}/editor-rtl.css +0 -0
  539. package/build-style/{comments-query-loop → comments}/editor.css +0 -0
  540. package/build-style/common-rtl.css +32 -0
  541. package/build-style/common.css +32 -0
  542. package/build-style/cover/style-rtl.css +0 -4
  543. package/build-style/cover/style.css +0 -4
  544. package/build-style/editor-rtl.css +16 -10
  545. package/build-style/editor.css +16 -10
  546. package/build-style/image/editor-rtl.css +1 -1
  547. package/build-style/image/editor.css +1 -1
  548. package/build-style/navigation/style-rtl.css +3 -0
  549. package/build-style/navigation/style.css +3 -0
  550. package/build-style/separator/editor-rtl.css +1 -0
  551. package/build-style/separator/editor.css +1 -0
  552. package/build-style/style-rtl.css +73 -4
  553. package/build-style/style.css +73 -4
  554. package/build-style/table/editor-rtl.css +8 -0
  555. package/build-style/table/editor.css +8 -0
  556. package/build-style/table/style-rtl.css +38 -0
  557. package/build-style/table/style.css +38 -0
  558. package/build-style/video/editor-rtl.css +2 -5
  559. package/build-style/video/editor.css +2 -5
  560. package/build-types/table-of-contents/list.d.ts +12 -0
  561. package/build-types/table-of-contents/list.d.ts.map +1 -0
  562. package/build-types/table-of-contents/utils.d.ts +24 -0
  563. package/build-types/table-of-contents/utils.d.ts.map +1 -0
  564. package/package.json +30 -29
  565. package/src/archives/edit.js +1 -1
  566. package/src/audio/edit.js +7 -10
  567. package/src/audio/edit.native.js +1 -1
  568. package/src/avatar/block.json +0 -1
  569. package/src/avatar/index.php +2 -2
  570. package/src/block/edit.js +39 -42
  571. package/src/block/test/edit.native.js +1 -1
  572. package/src/button/block.json +1 -0
  573. package/src/button/edit.native.js +6 -3
  574. package/src/categories/block.json +5 -1
  575. package/src/categories/edit.js +9 -3
  576. package/src/categories/index.php +1 -0
  577. package/src/column/block.json +10 -0
  578. package/src/comment-author-avatar/block.json +1 -0
  579. package/src/comment-template/edit.js +1 -5
  580. package/src/{comments-query-loop → comments}/block.json +1 -1
  581. package/src/{comments-query-loop → comments}/edit/comments-inspector-controls.js +0 -0
  582. package/src/{comments-query-loop → comments}/edit.js +1 -1
  583. package/src/{comments-query-loop → comments}/editor.scss +0 -0
  584. package/src/{comments-query-loop → comments}/index.js +0 -0
  585. package/src/{comments-query-loop → comments}/save.js +1 -3
  586. package/src/comments-title/index.js +1 -1
  587. package/src/common.scss +24 -1
  588. package/src/cover/controls.native.js +1 -2
  589. package/src/cover/edit/block-controls.js +119 -0
  590. package/src/cover/edit/cover-placeholder.js +39 -0
  591. package/src/cover/edit/index.js +381 -0
  592. package/src/cover/edit/inspector-controls.js +286 -0
  593. package/src/cover/edit/resizable-cover.js +55 -0
  594. package/src/cover/edit/use-cover-is-dark.js +71 -0
  595. package/src/cover/edit.native.js +40 -14
  596. package/src/cover/editor.scss +1 -1
  597. package/src/cover/focal-point-settings-button.native.js +1 -1
  598. package/src/cover/shared.js +4 -0
  599. package/src/cover/style.native.scss +4 -0
  600. package/src/cover/style.scss +0 -4
  601. package/src/cover/test/__snapshots__/edit.native.js.snap +6 -6
  602. package/src/cover/test/block-controls.js +62 -0
  603. package/src/cover/test/transforms.js +301 -0
  604. package/src/cover/transforms.js +112 -7
  605. package/src/cover/use-cover-is-dark.native.js +51 -0
  606. package/src/editor.scss +1 -1
  607. package/src/embed/edit.js +19 -24
  608. package/src/embed/edit.native.js +9 -14
  609. package/src/embed/embed-preview.js +4 -2
  610. package/src/embed/util.js +34 -2
  611. package/src/file/edit.native.js +0 -1
  612. package/src/file/inspector.js +1 -3
  613. package/src/gallery/edit.js +3 -2
  614. package/src/gallery/gallery.js +2 -2
  615. package/src/gallery/shared.js +3 -2
  616. package/src/gallery/use-get-media.js +2 -1
  617. package/src/gallery/use-short-code-transform.js +19 -16
  618. package/src/gallery/v1/edit.js +1 -1
  619. package/src/gallery/v1/gallery.js +2 -2
  620. package/src/group/block.json +1 -0
  621. package/src/heading/block.json +1 -0
  622. package/src/heading/edit.js +5 -2
  623. package/src/heading/transforms.js +4 -3
  624. package/src/html/edit.js +2 -2
  625. package/src/image/edit.js +11 -5
  626. package/src/image/edit.native.js +1 -2
  627. package/src/image/editor.scss +1 -1
  628. package/src/image/image.js +9 -3
  629. package/src/image/test/edit.native.js +7 -7
  630. package/src/index.js +52 -30
  631. package/src/index.native.js +12 -2
  632. package/src/is-block-metadata-experimental.js +19 -0
  633. package/src/latest-comments/edit.js +1 -1
  634. package/src/latest-posts/edit.js +27 -2
  635. package/src/latest-posts/edit.native.js +56 -1
  636. package/src/list/transforms.js +7 -0
  637. package/src/list/v2/edit.js +1 -0
  638. package/src/list/v2/migrate.js +1 -1
  639. package/src/list/v2/transforms.js +35 -0
  640. package/src/list-item/block.json +2 -1
  641. package/src/list-item/edit.js +17 -10
  642. package/src/list-item/hooks/index.js +3 -0
  643. package/src/list-item/hooks/use-backspace.js +52 -0
  644. package/src/list-item/hooks/use-enter.js +9 -16
  645. package/src/list-item/hooks/use-indent-list-item.js +50 -63
  646. package/src/list-item/hooks/use-space.js +48 -0
  647. package/src/list-item/hooks/use-split.js +24 -0
  648. package/src/list-item/utils.js +1 -1
  649. package/src/loginout/edit.js +1 -1
  650. package/src/media-text/edit.js +1 -2
  651. package/src/media-text/edit.native.js +4 -2
  652. package/src/media-text/media-container.native.js +2 -4
  653. package/src/media-text/transforms.js +154 -0
  654. package/src/navigation/block.json +1 -1
  655. package/src/navigation/edit/index.js +175 -169
  656. package/src/navigation/edit/inner-blocks.js +1 -8
  657. package/src/navigation/edit/unsaved-inner-blocks.js +5 -4
  658. package/src/navigation/index.php +5 -0
  659. package/src/navigation/style.scss +3 -0
  660. package/src/navigation/use-navigation-entities.js +1 -1
  661. package/src/navigation/view-modal.js +68 -0
  662. package/src/navigation/view.js +0 -35
  663. package/src/navigation-link/edit.js +1 -1
  664. package/src/navigation-link/fallback-variations.js +1 -1
  665. package/src/navigation-link/hooks.js +2 -2
  666. package/src/navigation-link/test/__snapshots__/hooks.js.snap +4 -4
  667. package/src/page-list/convert-to-links-modal.js +1 -1
  668. package/src/page-list/edit.js +1 -4
  669. package/src/paragraph/edit.js +6 -0
  670. package/src/paragraph/edit.native.js +13 -1
  671. package/src/paragraph/use-enter.js +103 -0
  672. package/src/post-author/edit.js +25 -23
  673. package/src/post-author-name/block.json +1 -0
  674. package/src/post-comment/block.json +2 -1
  675. package/src/post-comments/block.json +1 -1
  676. package/src/post-comments/edit.js +13 -43
  677. package/src/post-comments/index.php +2 -0
  678. package/src/post-comments-count/block.json +1 -0
  679. package/src/post-comments-form/edit.js +50 -58
  680. package/src/post-comments-form/form.js +40 -0
  681. package/src/post-comments-link/block.json +1 -0
  682. package/src/post-excerpt/edit.js +1 -1
  683. package/src/post-featured-image/edit.js +1 -1
  684. package/src/post-template/edit.js +5 -0
  685. package/src/post-terms/block.json +8 -0
  686. package/src/post-terms/edit.js +47 -1
  687. package/src/post-terms/hooks.js +27 -0
  688. package/src/post-terms/index.js +14 -7
  689. package/src/post-terms/index.php +50 -2
  690. package/src/post-title/index.js +1 -1
  691. package/src/pullquote/edit.js +2 -2
  692. package/src/pullquote/edit.native.js +2 -2
  693. package/src/query/block.json +2 -1
  694. package/src/query/edit/inspector-controls/index.js +25 -11
  695. package/src/query/edit/inspector-controls/parent-control.js +133 -0
  696. package/src/query/edit/inspector-controls/sticky-control.js +25 -0
  697. package/src/query/utils.js +22 -0
  698. package/src/query-title/index.js +1 -1
  699. package/src/query-title/variations.js +2 -2
  700. package/src/quote/block.json +1 -0
  701. package/src/quote/edit.js +5 -2
  702. package/src/quote/index.js +1 -1
  703. package/src/quote/v2/edit.js +7 -2
  704. package/src/rss/edit.js +1 -1
  705. package/src/search/edit.js +14 -7
  706. package/src/search/index.php +85 -34
  707. package/src/separator/block.json +3 -0
  708. package/src/separator/editor.scss +1 -0
  709. package/src/site-logo/edit.js +1 -1
  710. package/src/spacer/constants.js +1 -0
  711. package/src/spacer/controls.js +2 -2
  712. package/src/spacer/controls.native.js +1 -1
  713. package/src/spacer/edit.js +1 -2
  714. package/src/table/edit.js +30 -6
  715. package/src/table/editor.scss +13 -0
  716. package/src/table/style.scss +52 -0
  717. package/src/table-of-contents/block.json +9 -2
  718. package/src/table-of-contents/edit.js +155 -75
  719. package/src/table-of-contents/index.js +2 -0
  720. package/src/table-of-contents/list.tsx +46 -0
  721. package/src/table-of-contents/save.js +25 -0
  722. package/src/table-of-contents/utils.ts +71 -0
  723. package/src/tag-cloud/block.json +1 -1
  724. package/src/tag-cloud/edit.js +1 -1
  725. package/src/template-part/edit/index.js +25 -15
  726. package/src/template-part/edit/inner-blocks.js +2 -10
  727. package/src/video/edit.js +8 -7
  728. package/src/video/edit.native.js +1 -1
  729. package/src/video/editor.scss +3 -6
  730. package/test/babel-plugin.js +67 -0
  731. package/tsconfig.json +11 -0
  732. package/tsconfig.tsbuildinfo +1 -0
  733. package/build/comments-query-loop/edit/comments-inspector-controls.js.map +0 -1
  734. package/build/comments-query-loop/edit.js.map +0 -1
  735. package/build/comments-query-loop/index.js.map +0 -1
  736. package/build/comments-query-loop/save.js.map +0 -1
  737. package/build/cover/edit.js +0 -668
  738. package/build/cover/edit.js.map +0 -1
  739. package/build/post-terms/variations.js +0 -37
  740. package/build/post-terms/variations.js.map +0 -1
  741. package/build-module/comments-query-loop/edit.js.map +0 -1
  742. package/build-module/comments-query-loop/index.js.map +0 -1
  743. package/build-module/comments-query-loop/save.js.map +0 -1
  744. package/build-module/cover/edit.js +0 -645
  745. package/build-module/cover/edit.js.map +0 -1
  746. package/build-module/post-terms/variations.js +0 -27
  747. package/build-module/post-terms/variations.js.map +0 -1
  748. package/src/cover/edit.js +0 -827
  749. package/src/post-terms/variations.js +0 -28
  750. package/src/table-of-contents/index.php +0 -346
  751. package/src/table-of-contents/list.js +0 -28
  752. package/src/table-of-contents/utils.js +0 -126
@@ -11,23 +11,28 @@ import { isEqual } from 'lodash';
11
11
  import { BlockControls, BlockIcon, InspectorControls, store as blockEditorStore, useBlockProps } from '@wordpress/block-editor';
12
12
  import { createBlock, store as blocksStore } from '@wordpress/blocks';
13
13
  import { PanelBody, Placeholder, ToggleControl, ToolbarButton, ToolbarGroup } from '@wordpress/components';
14
+ import { useDisabled } from '@wordpress/compose';
14
15
  import { useDispatch, useSelect } from '@wordpress/data';
15
- import { renderToString, useEffect, useState } from '@wordpress/element';
16
+ import { __unstableStripHTML as stripHTML } from '@wordpress/dom';
17
+ import { renderToString, useEffect } from '@wordpress/element';
16
18
  import { __ } from '@wordpress/i18n';
19
+ import { addQueryArgs, removeQueryArgs } from '@wordpress/url';
17
20
  /**
18
21
  * Internal dependencies
19
22
  */
20
23
 
24
+ import icon from './icon';
21
25
  import TableOfContentsList from './list';
22
- import { getHeadingsFromContent, linearToNestedHeadingList } from './utils';
26
+ import { linearToNestedHeadingList } from './utils';
27
+ /** @typedef {import('./utils').HeadingData} HeadingData */
28
+
23
29
  /**
24
30
  * Table of Contents block edit component.
25
31
  *
26
32
  * @param {Object} props The props.
27
33
  * @param {Object} props.attributes The block attributes.
28
- * @param {boolean} props.attributes.onlyIncludeCurrentPage
29
- * Whether to only include headings from the current page (if the post is
30
- * paginated).
34
+ * @param {HeadingData[]} props.attributes.headings A list of data for each heading in the post.
35
+ * @param {boolean} props.attributes.onlyIncludeCurrentPage Whether to only include headings from the current page (if the post is paginated).
31
36
  * @param {string} props.clientId
32
37
  * @param {(attributes: Object) => void} props.setAttributes
33
38
  *
@@ -37,96 +42,157 @@ import { getHeadingsFromContent, linearToNestedHeadingList } from './utils';
37
42
  export default function TableOfContentsEdit(_ref) {
38
43
  let {
39
44
  attributes: {
45
+ headings = [],
40
46
  onlyIncludeCurrentPage
41
47
  },
42
48
  clientId,
43
49
  setAttributes
44
50
  } = _ref;
45
- const blockProps = useBlockProps(); // Local state; not saved to block attributes. The saved block is dynamic and uses PHP to generate its content.
46
-
47
- const [headings, setHeadings] = useState([]);
48
- const [headingTree, setHeadingTree] = useState([]);
51
+ const blockProps = useBlockProps();
52
+ const disabledRef = useDisabled();
53
+ const listBlockExists = useSelect(select => !!select(blocksStore).getBlockType('core/list'), []);
49
54
  const {
50
- listBlockExists,
51
- postContent
52
- } = useSelect(select => ({
53
- listBlockExists: !!select(blocksStore).getBlockType('core/list'),
54
- // FIXME: @wordpress/block-library should not depend on @wordpress/editor.
55
- // Blocks can be loaded into a *non-post* block editor.
56
- // eslint-disable-next-line @wordpress/data-no-store-string-literals
57
- postContent: select('core/editor').getEditedPostContent()
58
- }), []); // The page this block would be part of on the front-end. For performance
59
- // reasons, this is only calculated when onlyIncludeCurrentPage is true.
60
-
61
- const pageIndex = useSelect(select => {
62
- if (!onlyIncludeCurrentPage) {
63
- return null;
64
- }
55
+ __unstableMarkNextChangeAsNotPersistent,
56
+ replaceBlocks
57
+ } = useDispatch(blockEditorStore);
58
+ /**
59
+ * The latest heading data, or null if the new data deeply equals the saved
60
+ * headings attribute.
61
+ *
62
+ * Since useSelect forces a re-render when its return value is shallowly
63
+ * inequal to its prior call, we would be re-rendering this block every time
64
+ * the stores change, even if the latest headings were deeply equal to the
65
+ * ones saved in the block attributes.
66
+ *
67
+ * By returning null when they're equal, we reduce that to 2 renders: one
68
+ * when there are new latest headings (and so it returns them), and one when
69
+ * they haven't changed (so it returns null). As long as the latest heading
70
+ * data remains the same, further calls of the useSelect callback will
71
+ * continue to return null, thus preventing any forced re-renders.
72
+ */
73
+
74
+ const latestHeadings = useSelect(select => {
75
+ var _editorSelectors$getP;
65
76
 
66
77
  const {
67
78
  getBlockAttributes,
68
- getBlockIndex,
69
79
  getBlockName,
70
- getBlockOrder
71
- } = select(blockEditorStore);
72
- const blockIndex = getBlockIndex(clientId);
73
- const blockOrder = getBlockOrder(); // Calculate which page the block will appear in on the front-end by
74
- // counting how many <!--nextpage--> tags precede it.
75
- // Unfortunately, this implementation only accounts for Page Break and
76
- // Classic blocks, so if there are any <!--nextpage--> tags in any
77
- // other block, they won't be counted. This will result in the table
78
- // of contents showing headings from the wrong page if
79
- // onlyIncludeCurrentPage === true. Thankfully, this issue only
80
- // affects the editor implementation.
81
-
82
- let page = 1;
83
-
84
- for (let i = 0; i < blockIndex; i++) {
85
- const blockName = getBlockName(blockOrder[i]);
80
+ getClientIdsWithDescendants,
81
+ __experimentalGetGlobalBlocksByName: getGlobalBlocksByName
82
+ } = select(blockEditorStore); // FIXME: @wordpress/block-library should not depend on @wordpress/editor.
83
+ // Blocks can be loaded into a *non-post* block editor, so to avoid
84
+ // declaring @wordpress/editor as a dependency, we must access its
85
+ // store by string. When the store is not available, editorSelectors
86
+ // will be null, and the block's saved markup will lack permalinks.
87
+ // eslint-disable-next-line @wordpress/data-no-store-string-literals
86
88
 
87
- if (blockName === 'core/nextpage') {
88
- page++;
89
- } else if (blockName === 'core/freeform') {
90
- var _getBlockAttributes$c;
89
+ const editorSelectors = select('core/editor');
90
+ const pageBreakClientIds = getGlobalBlocksByName('core/nextpage');
91
+ const isPaginated = pageBreakClientIds.length !== 0; // Get the client ids of all blocks in the editor.
92
+
93
+ const allBlockClientIds = getClientIdsWithDescendants(); // 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.
94
+
95
+ let tocPage = 1;
96
+
97
+ if (isPaginated && onlyIncludeCurrentPage) {
98
+ // We can't use getBlockIndex because it only returns the index
99
+ // relative to sibling blocks.
100
+ const tocIndex = allBlockClientIds.indexOf(clientId);
91
101
 
92
- // Count the page breaks inside the Classic block.
93
- const pageBreaks = (_getBlockAttributes$c = getBlockAttributes(blockOrder[i]).content) === null || _getBlockAttributes$c === void 0 ? void 0 : _getBlockAttributes$c.match(/<!--nextpage-->/g);
102
+ for (const [blockIndex, blockClientId] of allBlockClientIds.entries()) {
103
+ // If we've reached blocks after the Table of Contents, we've
104
+ // finished calculating which page the block is on.
105
+ if (blockIndex >= tocIndex) {
106
+ break;
107
+ }
94
108
 
95
- if (pageBreaks !== null && pageBreaks !== undefined) {
96
- page += pageBreaks.length;
109
+ if (getBlockName(blockClientId) === 'core/nextpage') {
110
+ tocPage++;
97
111
  }
98
112
  }
99
113
  }
100
114
 
101
- return page;
102
- }, [clientId, onlyIncludeCurrentPage]);
103
- useEffect(() => {
104
- let latestHeadings;
115
+ const _latestHeadings = [];
116
+ /** The page (of a paginated post) a heading will be part of. */
117
+
118
+ let headingPage = 1;
119
+ /**
120
+ * A permalink to the current post. If the core/editor store is
121
+ * unavailable, this variable will be null.
122
+ */
123
+
124
+ const permalink = (_editorSelectors$getP = editorSelectors === null || editorSelectors === void 0 ? void 0 : editorSelectors.getPermalink()) !== null && _editorSelectors$getP !== void 0 ? _editorSelectors$getP : null;
125
+ let headingPageLink = null; // If the core/editor store is available, we can add permalinks to the
126
+ // generated table of contents.
105
127
 
106
- if (onlyIncludeCurrentPage) {
107
- const pagesOfContent = postContent.split('<!--nextpage-->');
108
- latestHeadings = getHeadingsFromContent(pagesOfContent[pageIndex - 1]);
109
- } else {
110
- latestHeadings = getHeadingsFromContent(postContent);
128
+ if (typeof permalink === 'string') {
129
+ headingPageLink = isPaginated ? addQueryArgs(permalink, {
130
+ page: headingPage
131
+ }) : permalink;
111
132
  }
112
133
 
113
- if (!isEqual(headings, latestHeadings)) {
114
- setHeadings(latestHeadings);
115
- setHeadingTree(linearToNestedHeadingList(latestHeadings));
134
+ for (const blockClientId of allBlockClientIds) {
135
+ const blockName = getBlockName(blockClientId);
136
+
137
+ if (blockName === 'core/nextpage') {
138
+ headingPage++; // If we're only including headings from the current page (of
139
+ // a paginated post), then exit the loop if we've reached the
140
+ // pages after the one with the Table of Contents block.
141
+
142
+ if (onlyIncludeCurrentPage && headingPage > tocPage) {
143
+ break;
144
+ }
145
+
146
+ if (typeof permalink === 'string') {
147
+ headingPageLink = addQueryArgs(removeQueryArgs(permalink, ['page']), {
148
+ page: headingPage
149
+ });
150
+ }
151
+ } // If we're including all headings or we've reached headings on
152
+ // the same page as the Table of Contents block, add them to the
153
+ // list.
154
+ else if (!onlyIncludeCurrentPage || headingPage === tocPage) {
155
+ if (blockName === 'core/heading') {
156
+ const headingAttributes = getBlockAttributes(blockClientId);
157
+ const canBeLinked = typeof headingPageLink === 'string' && typeof headingAttributes.anchor === 'string' && headingAttributes.anchor !== '';
158
+
159
+ _latestHeadings.push({
160
+ content: stripHTML(headingAttributes.content),
161
+ level: headingAttributes.level,
162
+ link: canBeLinked ? `${headingPageLink}#${headingAttributes.anchor}` : null
163
+ });
164
+ }
165
+ }
116
166
  }
117
- }, [pageIndex, postContent, onlyIncludeCurrentPage]);
118
- const {
119
- replaceBlocks
120
- } = useDispatch(blockEditorStore);
167
+
168
+ if (isEqual(headings, _latestHeadings)) {
169
+ return null;
170
+ }
171
+
172
+ return _latestHeadings;
173
+ }, [clientId, onlyIncludeCurrentPage, headings]);
174
+ useEffect(() => {
175
+ if (latestHeadings !== null) {
176
+ // This is required to keep undo working and not create 2 undo steps
177
+ // for each heading change.
178
+ __unstableMarkNextChangeAsNotPersistent();
179
+
180
+ setAttributes({
181
+ headings: latestHeadings
182
+ });
183
+ }
184
+ }, [latestHeadings]);
185
+ const headingTree = linearToNestedHeadingList(headings);
121
186
  const toolbarControls = listBlockExists && createElement(BlockControls, null, createElement(ToolbarGroup, null, createElement(ToolbarButton, {
122
187
  onClick: () => replaceBlocks(clientId, createBlock('core/list', {
188
+ ordered: true,
123
189
  values: renderToString(createElement(TableOfContentsList, {
124
190
  nestedHeadingList: headingTree
125
191
  }))
126
192
  }))
127
193
  }, __('Convert to static list'))));
128
194
  const inspectorControls = createElement(InspectorControls, null, createElement(PanelBody, {
129
- title: __('Table of Contents settings')
195
+ title: __('Settings')
130
196
  }, createElement(ToggleControl, {
131
197
  label: __('Only include current page'),
132
198
  checked: onlyIncludeCurrentPage,
@@ -141,14 +207,16 @@ export default function TableOfContentsEdit(_ref) {
141
207
  if (headings.length === 0) {
142
208
  return createElement(Fragment, null, createElement("div", blockProps, createElement(Placeholder, {
143
209
  icon: createElement(BlockIcon, {
144
- icon: "list-view"
210
+ icon: icon
145
211
  }),
146
212
  label: "Table of Contents",
147
213
  instructions: __('Start adding Heading blocks to create a table of contents. Headings with HTML anchors will be linked here.')
148
214
  })), inspectorControls);
149
215
  }
150
216
 
151
- return createElement(Fragment, null, createElement("nav", blockProps, createElement("ul", null, createElement(TableOfContentsList, {
217
+ return createElement(Fragment, null, createElement("nav", blockProps, createElement("ol", {
218
+ ref: disabledRef
219
+ }, createElement(TableOfContentsList, {
152
220
  nestedHeadingList: headingTree
153
221
  }))), toolbarControls, inspectorControls);
154
222
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-library/src/table-of-contents/edit.js"],"names":["isEqual","BlockControls","BlockIcon","InspectorControls","store","blockEditorStore","useBlockProps","createBlock","blocksStore","PanelBody","Placeholder","ToggleControl","ToolbarButton","ToolbarGroup","useDispatch","useSelect","renderToString","useEffect","useState","__","TableOfContentsList","getHeadingsFromContent","linearToNestedHeadingList","TableOfContentsEdit","attributes","onlyIncludeCurrentPage","clientId","setAttributes","blockProps","headings","setHeadings","headingTree","setHeadingTree","listBlockExists","postContent","select","getBlockType","getEditedPostContent","pageIndex","getBlockAttributes","getBlockIndex","getBlockName","getBlockOrder","blockIndex","blockOrder","page","i","blockName","pageBreaks","content","match","undefined","length","latestHeadings","pagesOfContent","split","replaceBlocks","toolbarControls","values","inspectorControls","value"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,OAAT,QAAwB,QAAxB;AAEA;AACA;AACA;;AACA,SACCC,aADD,EAECC,SAFD,EAGCC,iBAHD,EAICC,KAAK,IAAIC,gBAJV,EAKCC,aALD,QAMO,yBANP;AAOA,SAASC,WAAT,EAAsBH,KAAK,IAAII,WAA/B,QAAkD,mBAAlD;AACA,SACCC,SADD,EAECC,WAFD,EAGCC,aAHD,EAICC,aAJD,EAKCC,YALD,QAMO,uBANP;AAOA,SAASC,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SAASC,cAAT,EAAyBC,SAAzB,EAAoCC,QAApC,QAAoD,oBAApD;AACA,SAASC,EAAT,QAAmB,iBAAn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iBAAiB,EAAGG;AAAzC,IADD,CADD,CADD,EAMG0B,eANH,EAOGE,iBAPH,CADD;AAWA","sourcesContent":["/**\n * External dependencies\n */\nimport { isEqual } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tBlockControls,\n\tBlockIcon,\n\tInspectorControls,\n\tstore as blockEditorStore,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport { createBlock, store as blocksStore } from '@wordpress/blocks';\nimport {\n\tPanelBody,\n\tPlaceholder,\n\tToggleControl,\n\tToolbarButton,\n\tToolbarGroup,\n} from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { renderToString, useEffect, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport TableOfContentsList from './list';\nimport { getHeadingsFromContent, linearToNestedHeadingList } from './utils';\n\n/**\n * Table of Contents block edit component.\n *\n * @param {Object} props The props.\n * @param {Object} props.attributes The block attributes.\n * @param {boolean} props.attributes.onlyIncludeCurrentPage\n * Whether to only include headings from the current page (if the post is\n * paginated).\n * @param {string} props.clientId\n * @param {(attributes: Object) => void} props.setAttributes\n *\n * @return {WPComponent} The component.\n */\nexport default function TableOfContentsEdit( {\n\tattributes: { onlyIncludeCurrentPage },\n\tclientId,\n\tsetAttributes,\n} ) {\n\tconst blockProps = useBlockProps();\n\n\t// Local state; not saved to block attributes. The saved block is dynamic and uses PHP to generate its content.\n\tconst [ headings, setHeadings ] = useState( [] );\n\tconst [ headingTree, setHeadingTree ] = useState( [] );\n\n\tconst { listBlockExists, postContent } = useSelect(\n\t\t( select ) => ( {\n\t\t\tlistBlockExists: !! select( blocksStore ).getBlockType(\n\t\t\t\t'core/list'\n\t\t\t),\n\t\t\t// FIXME: @wordpress/block-library should not depend on @wordpress/editor.\n\t\t\t// Blocks can be loaded into a *non-post* block editor.\n\t\t\t// eslint-disable-next-line @wordpress/data-no-store-string-literals\n\t\t\tpostContent: select( 'core/editor' ).getEditedPostContent(),\n\t\t} ),\n\t\t[]\n\t);\n\n\t// The page this block would be part of on the front-end. For performance\n\t// reasons, this is only calculated when onlyIncludeCurrentPage is true.\n\tconst pageIndex = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! onlyIncludeCurrentPage ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst {\n\t\t\t\tgetBlockAttributes,\n\t\t\t\tgetBlockIndex,\n\t\t\t\tgetBlockName,\n\t\t\t\tgetBlockOrder,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\tconst blockIndex = getBlockIndex( clientId );\n\t\t\tconst blockOrder = getBlockOrder();\n\n\t\t\t// Calculate which page the block will appear in on the front-end by\n\t\t\t// counting how many <!--nextpage--> tags precede it.\n\t\t\t// Unfortunately, this implementation only accounts for Page Break and\n\t\t\t// Classic blocks, so if there are any <!--nextpage--> tags in any\n\t\t\t// other block, they won't be counted. This will result in the table\n\t\t\t// of contents showing headings from the wrong page if\n\t\t\t// onlyIncludeCurrentPage === true. Thankfully, this issue only\n\t\t\t// affects the editor implementation.\n\t\t\tlet page = 1;\n\t\t\tfor ( let i = 0; i < blockIndex; i++ ) {\n\t\t\t\tconst blockName = getBlockName( blockOrder[ i ] );\n\t\t\t\tif ( blockName === 'core/nextpage' ) {\n\t\t\t\t\tpage++;\n\t\t\t\t} else if ( blockName === 'core/freeform' ) {\n\t\t\t\t\t// Count the page breaks inside the Classic block.\n\t\t\t\t\tconst pageBreaks = getBlockAttributes(\n\t\t\t\t\t\tblockOrder[ i ]\n\t\t\t\t\t).content?.match( /<!--nextpage-->/g );\n\n\t\t\t\t\tif ( pageBreaks !== null && pageBreaks !== undefined ) {\n\t\t\t\t\t\tpage += pageBreaks.length;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn page;\n\t\t},\n\t\t[ clientId, onlyIncludeCurrentPage ]\n\t);\n\n\tuseEffect( () => {\n\t\tlet latestHeadings;\n\n\t\tif ( onlyIncludeCurrentPage ) {\n\t\t\tconst pagesOfContent = postContent.split( '<!--nextpage-->' );\n\n\t\t\tlatestHeadings = getHeadingsFromContent(\n\t\t\t\tpagesOfContent[ pageIndex - 1 ]\n\t\t\t);\n\t\t} else {\n\t\t\tlatestHeadings = getHeadingsFromContent( postContent );\n\t\t}\n\n\t\tif ( ! isEqual( headings, latestHeadings ) ) {\n\t\t\tsetHeadings( latestHeadings );\n\t\t\tsetHeadingTree( linearToNestedHeadingList( latestHeadings ) );\n\t\t}\n\t}, [ pageIndex, postContent, onlyIncludeCurrentPage ] );\n\n\tconst { replaceBlocks } = useDispatch( blockEditorStore );\n\n\tconst toolbarControls = listBlockExists && (\n\t\t<BlockControls>\n\t\t\t<ToolbarGroup>\n\t\t\t\t<ToolbarButton\n\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\treplaceBlocks(\n\t\t\t\t\t\t\tclientId,\n\t\t\t\t\t\t\tcreateBlock( 'core/list', {\n\t\t\t\t\t\t\t\tvalues: renderToString(\n\t\t\t\t\t\t\t\t\t<TableOfContentsList\n\t\t\t\t\t\t\t\t\t\tnestedHeadingList={ headingTree }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Convert to static list' ) }\n\t\t\t\t</ToolbarButton>\n\t\t\t</ToolbarGroup>\n\t\t</BlockControls>\n\t);\n\n\tconst inspectorControls = (\n\t\t<InspectorControls>\n\t\t\t<PanelBody title={ __( 'Table of Contents settings' ) }>\n\t\t\t\t<ToggleControl\n\t\t\t\t\tlabel={ __( 'Only include current page' ) }\n\t\t\t\t\tchecked={ onlyIncludeCurrentPage }\n\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\tsetAttributes( { onlyIncludeCurrentPage: value } )\n\t\t\t\t\t}\n\t\t\t\t\thelp={\n\t\t\t\t\t\tonlyIncludeCurrentPage\n\t\t\t\t\t\t\t? __(\n\t\t\t\t\t\t\t\t\t'Only including headings from the current page (if the post is paginated).'\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\t\t'Toggle to only include headings from the current page (if the post is paginated).'\n\t\t\t\t\t\t\t )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</PanelBody>\n\t\t</InspectorControls>\n\t);\n\n\t// If there are no headings or the only heading is empty.\n\t// Note that the toolbar controls are intentionally omitted since the\n\t// \"Convert to static list\" option is useless to the placeholder state.\n\tif ( headings.length === 0 ) {\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<div { ...blockProps }>\n\t\t\t\t\t<Placeholder\n\t\t\t\t\t\ticon={ <BlockIcon icon=\"list-view\" /> }\n\t\t\t\t\t\tlabel=\"Table of Contents\"\n\t\t\t\t\t\tinstructions={ __(\n\t\t\t\t\t\t\t'Start adding Heading blocks to create a table of contents. Headings with HTML anchors will be linked here.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t\t{ inspectorControls }\n\t\t\t</>\n\t\t);\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<nav { ...blockProps }>\n\t\t\t\t<ul>\n\t\t\t\t\t<TableOfContentsList nestedHeadingList={ headingTree } />\n\t\t\t\t</ul>\n\t\t\t</nav>\n\t\t\t{ toolbarControls }\n\t\t\t{ inspectorControls }\n\t\t</>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-library/src/table-of-contents/edit.js"],"names":["isEqual","BlockControls","BlockIcon","InspectorControls","store","blockEditorStore","useBlockProps","createBlock","blocksStore","PanelBody","Placeholder","ToggleControl","ToolbarButton","ToolbarGroup","useDisabled","useDispatch","useSelect","__unstableStripHTML","stripHTML","renderToString","useEffect","__","addQueryArgs","removeQueryArgs","icon","TableOfContentsList","linearToNestedHeadingList","TableOfContentsEdit","attributes","headings","onlyIncludeCurrentPage","clientId","setAttributes","blockProps","disabledRef","listBlockExists","select","getBlockType","__unstableMarkNextChangeAsNotPersistent","replaceBlocks","latestHeadings","getBlockAttributes","getBlockName","getClientIdsWithDescendants","__experimentalGetGlobalBlocksByName","getGlobalBlocksByName","editorSelectors","pageBreakClientIds","isPaginated","length","allBlockClientIds","tocPage","tocIndex","indexOf","blockIndex","blockClientId","entries","_latestHeadings","headingPage","permalink","getPermalink","headingPageLink","page","blockName","headingAttributes","canBeLinked","anchor","push","content","level","link","headingTree","toolbarControls","ordered","values","inspectorControls","value"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,OAAT,QAAwB,QAAxB;AAEA;AACA;AACA;;AACA,SACCC,aADD,EAECC,SAFD,EAGCC,iBAHD,EAICC,KAAK,IAAIC,gBAJV,EAKCC,aALD,QAMO,yBANP;AAOA,SAASC,WAAT,EAAsBH,KAAK,IAAII,WAA/B,QAAkD,mBAAlD;AACA,SACCC,SADD,EAECC,WAFD,EAGCC,aAHD,EAICC,aAJD,EAKCC,YALD,QAMO,uBANP;AAOA,SAASC,WAAT,QAA4B,oBAA5B;AACA,SAASC,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SAASC,mBAAmB,IAAIC,SAAhC,QAAiD,gBAAjD;AACA,SAASC,cAAT,EAAyBC,SAAzB,QAA0C,oBAA1C;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,YAAT,EAAuBC,eAAvB,QAA8C,gBAA9C;AAEA;AACA;AACA;;AACA,OAAOC,IAAP,MAAiB,QAAjB;AACA,OAAOC,mBAAP,MAAgC,QAAhC;AACA,SAASC,yBAAT,QAA0C,SAA1C;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,mBAAT,OAIX;AAAA,MAJyC;AAC5CC,IAAAA,UAAU,EAAE;AAAEC,MAAAA,QAAQ,GAAG,EAAb;AAAiBC,MAAAA;AAAjB,KADgC;AAE5CC,IAAAA,QAF4C;AAG5CC,IAAAA;A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C,iBAAD,QACC,cAAC,SAAD;AAAW,IAAA,KAAK,EAAGtD,EAAE,CAAE,UAAF;AAArB,KACC,cAAC,aAAD;AACC,IAAA,KAAK,EAAGA,EAAE,CAAE,2BAAF,CADX;AAEC,IAAA,OAAO,EAAGS,sBAFX;AAGC,IAAA,QAAQ,EAAK8C,KAAF,IACV5C,aAAa,CAAE;AAAEF,MAAAA,sBAAsB,EAAE8C;AAA1B,KAAF,CAJf;AAMC,IAAA,IAAI,EACH9C,sBAAsB,GACnBT,EAAE,CACF,2EADE,CADiB,GAInBA,EAAE,CACF,mFADE;AAXP,IADD,CADD,CADD,CA3LG,CAkNH;AACA;AACA;;AACA,MAAKQ,QAAQ,CAACoB,MAAT,KAAoB,CAAzB,EAA6B;AAC5B,WACC,8BACC,qBAAUhB,UAAV,EACC,cAAC,WAAD;AACC,MAAA,IAAI,EAAG,cAAC,SAAD;AAAW,QAAA,IAAI,EAAGT;AAAlB,QADR;AAEC,MAAA,KAAK,EAAC,mBAFP;AAGC,MAAA,YAAY,EAAGH,EAAE,CAChB,4GADgB;AAHlB,MADD,CADD,EAUGsD,iBAVH,CADD;AAcA;;AAED,SACC,8BACC,qBAAU1C,UAAV,EACC;AAAI,IAAA,GAAG,EAAGC;AAAV,KACC,cAAC,mBAAD;AAAqB,IAAA,iBAAiB,EAAGqC;AAAzC,IADD,CADD,CADD,EAMGC,eANH,EAOGG,iBAPH,CADD;AAWA","sourcesContent":["/**\n * External dependencies\n */\nimport { isEqual } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tBlockControls,\n\tBlockIcon,\n\tInspectorControls,\n\tstore as blockEditorStore,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport { createBlock, store as blocksStore } from '@wordpress/blocks';\nimport {\n\tPanelBody,\n\tPlaceholder,\n\tToggleControl,\n\tToolbarButton,\n\tToolbarGroup,\n} from '@wordpress/components';\nimport { useDisabled } from '@wordpress/compose';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\nimport { renderToString, useEffect } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { addQueryArgs, removeQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport icon from './icon';\nimport TableOfContentsList from './list';\nimport { linearToNestedHeadingList } from './utils';\n\n/** @typedef {import('./utils').HeadingData} HeadingData */\n\n/**\n * Table of Contents block edit component.\n *\n * @param {Object} props The props.\n * @param {Object} props.attributes The block attributes.\n * @param {HeadingData[]} props.attributes.headings A list of data for each heading in the post.\n * @param {boolean} props.attributes.onlyIncludeCurrentPage Whether to only include headings from the current page (if the post is paginated).\n * @param {string} props.clientId\n * @param {(attributes: Object) => void} props.setAttributes\n *\n * @return {WPComponent} The component.\n */\nexport default function TableOfContentsEdit( {\n\tattributes: { headings = [], onlyIncludeCurrentPage },\n\tclientId,\n\tsetAttributes,\n} ) {\n\tconst blockProps = useBlockProps();\n\tconst disabledRef = useDisabled();\n\n\tconst listBlockExists = useSelect(\n\t\t( select ) => !! select( blocksStore ).getBlockType( 'core/list' ),\n\t\t[]\n\t);\n\n\tconst {\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t\treplaceBlocks,\n\t} = useDispatch( blockEditorStore );\n\n\t/**\n\t * The latest heading data, or null if the new data deeply equals the saved\n\t * headings attribute.\n\t *\n\t * Since useSelect forces a re-render when its return value is shallowly\n\t * inequal to its prior call, we would be re-rendering this block every time\n\t * the stores change, even if the latest headings were deeply equal to the\n\t * ones saved in the block attributes.\n\t *\n\t * By returning null when they're equal, we reduce that to 2 renders: one\n\t * when there are new latest headings (and so it returns them), and one when\n\t * they haven't changed (so it returns null). As long as the latest heading\n\t * data remains the same, further calls of the useSelect callback will\n\t * continue to return null, thus preventing any forced re-renders.\n\t */\n\tconst latestHeadings = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockAttributes,\n\t\t\t\tgetBlockName,\n\t\t\t\tgetClientIdsWithDescendants,\n\t\t\t\t__experimentalGetGlobalBlocksByName: getGlobalBlocksByName,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\t// FIXME: @wordpress/block-library should not depend on @wordpress/editor.\n\t\t\t// Blocks can be loaded into a *non-post* block editor, so to avoid\n\t\t\t// declaring @wordpress/editor as a dependency, we must access its\n\t\t\t// store by string. When the store is not available, editorSelectors\n\t\t\t// will be null, and the block's saved markup will lack permalinks.\n\t\t\t// eslint-disable-next-line @wordpress/data-no-store-string-literals\n\t\t\tconst editorSelectors = select( 'core/editor' );\n\n\t\t\tconst pageBreakClientIds = getGlobalBlocksByName( 'core/nextpage' );\n\n\t\t\tconst isPaginated = pageBreakClientIds.length !== 0;\n\n\t\t\t// Get the client ids of all blocks in the editor.\n\t\t\tconst allBlockClientIds = getClientIdsWithDescendants();\n\n\t\t\t// 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.\n\t\t\tlet tocPage = 1;\n\n\t\t\tif ( isPaginated && onlyIncludeCurrentPage ) {\n\t\t\t\t// We can't use getBlockIndex because it only returns the index\n\t\t\t\t// relative to sibling blocks.\n\t\t\t\tconst tocIndex = allBlockClientIds.indexOf( clientId );\n\n\t\t\t\tfor ( const [\n\t\t\t\t\tblockIndex,\n\t\t\t\t\tblockClientId,\n\t\t\t\t] of allBlockClientIds.entries() ) {\n\t\t\t\t\t// If we've reached blocks after the Table of Contents, we've\n\t\t\t\t\t// finished calculating which page the block is on.\n\t\t\t\t\tif ( blockIndex >= tocIndex ) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tif ( getBlockName( blockClientId ) === 'core/nextpage' ) {\n\t\t\t\t\t\ttocPage++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst _latestHeadings = [];\n\n\t\t\t/** The page (of a paginated post) a heading will be part of. */\n\t\t\tlet headingPage = 1;\n\n\t\t\t/**\n\t\t\t * A permalink to the current post. If the core/editor store is\n\t\t\t * unavailable, this variable will be null.\n\t\t\t */\n\t\t\tconst permalink = editorSelectors?.getPermalink() ?? null;\n\n\t\t\tlet headingPageLink = null;\n\n\t\t\t// If the core/editor store is available, we can add permalinks to the\n\t\t\t// generated table of contents.\n\t\t\tif ( typeof permalink === 'string' ) {\n\t\t\t\theadingPageLink = isPaginated\n\t\t\t\t\t? addQueryArgs( permalink, { page: headingPage } )\n\t\t\t\t\t: permalink;\n\t\t\t}\n\n\t\t\tfor ( const blockClientId of allBlockClientIds ) {\n\t\t\t\tconst blockName = getBlockName( blockClientId );\n\t\t\t\tif ( blockName === 'core/nextpage' ) {\n\t\t\t\t\theadingPage++;\n\n\t\t\t\t\t// If we're only including headings from the current page (of\n\t\t\t\t\t// a paginated post), then exit the loop if we've reached the\n\t\t\t\t\t// pages after the one with the Table of Contents block.\n\t\t\t\t\tif ( onlyIncludeCurrentPage && headingPage > tocPage ) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( typeof permalink === 'string' ) {\n\t\t\t\t\t\theadingPageLink = addQueryArgs(\n\t\t\t\t\t\t\tremoveQueryArgs( permalink, [ 'page' ] ),\n\t\t\t\t\t\t\t{ page: headingPage }\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// If we're including all headings or we've reached headings on\n\t\t\t\t// the same page as the Table of Contents block, add them to the\n\t\t\t\t// list.\n\t\t\t\telse if (\n\t\t\t\t\t! onlyIncludeCurrentPage ||\n\t\t\t\t\theadingPage === tocPage\n\t\t\t\t) {\n\t\t\t\t\tif ( blockName === 'core/heading' ) {\n\t\t\t\t\t\tconst headingAttributes = getBlockAttributes(\n\t\t\t\t\t\t\tblockClientId\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tconst canBeLinked =\n\t\t\t\t\t\t\ttypeof headingPageLink === 'string' &&\n\t\t\t\t\t\t\ttypeof headingAttributes.anchor === 'string' &&\n\t\t\t\t\t\t\theadingAttributes.anchor !== '';\n\n\t\t\t\t\t\t_latestHeadings.push( {\n\t\t\t\t\t\t\tcontent: stripHTML( headingAttributes.content ),\n\t\t\t\t\t\t\tlevel: headingAttributes.level,\n\t\t\t\t\t\t\tlink: canBeLinked\n\t\t\t\t\t\t\t\t? `${ headingPageLink }#${ headingAttributes.anchor }`\n\t\t\t\t\t\t\t\t: null,\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( isEqual( headings, _latestHeadings ) ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn _latestHeadings;\n\t\t},\n\t\t[ clientId, onlyIncludeCurrentPage, headings ]\n\t);\n\n\tuseEffect( () => {\n\t\tif ( latestHeadings !== null ) {\n\t\t\t// This is required to keep undo working and not create 2 undo steps\n\t\t\t// for each heading change.\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\tsetAttributes( { headings: latestHeadings } );\n\t\t}\n\t}, [ latestHeadings ] );\n\n\tconst headingTree = linearToNestedHeadingList( headings );\n\n\tconst toolbarControls = listBlockExists && (\n\t\t<BlockControls>\n\t\t\t<ToolbarGroup>\n\t\t\t\t<ToolbarButton\n\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\treplaceBlocks(\n\t\t\t\t\t\t\tclientId,\n\t\t\t\t\t\t\tcreateBlock( 'core/list', {\n\t\t\t\t\t\t\t\tordered: true,\n\t\t\t\t\t\t\t\tvalues: renderToString(\n\t\t\t\t\t\t\t\t\t<TableOfContentsList\n\t\t\t\t\t\t\t\t\t\tnestedHeadingList={ headingTree }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Convert to static list' ) }\n\t\t\t\t</ToolbarButton>\n\t\t\t</ToolbarGroup>\n\t\t</BlockControls>\n\t);\n\n\tconst inspectorControls = (\n\t\t<InspectorControls>\n\t\t\t<PanelBody title={ __( 'Settings' ) }>\n\t\t\t\t<ToggleControl\n\t\t\t\t\tlabel={ __( 'Only include current page' ) }\n\t\t\t\t\tchecked={ onlyIncludeCurrentPage }\n\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\tsetAttributes( { onlyIncludeCurrentPage: value } )\n\t\t\t\t\t}\n\t\t\t\t\thelp={\n\t\t\t\t\t\tonlyIncludeCurrentPage\n\t\t\t\t\t\t\t? __(\n\t\t\t\t\t\t\t\t\t'Only including headings from the current page (if the post is paginated).'\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\t\t'Toggle to only include headings from the current page (if the post is paginated).'\n\t\t\t\t\t\t\t )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</PanelBody>\n\t\t</InspectorControls>\n\t);\n\n\t// If there are no headings or the only heading is empty.\n\t// Note that the toolbar controls are intentionally omitted since the\n\t// \"Convert to static list\" option is useless to the placeholder state.\n\tif ( headings.length === 0 ) {\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<div { ...blockProps }>\n\t\t\t\t\t<Placeholder\n\t\t\t\t\t\ticon={ <BlockIcon icon={ icon } /> }\n\t\t\t\t\t\tlabel=\"Table of Contents\"\n\t\t\t\t\t\tinstructions={ __(\n\t\t\t\t\t\t\t'Start adding Heading blocks to create a table of contents. Headings with HTML anchors will be linked here.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t\t{ inspectorControls }\n\t\t\t</>\n\t\t);\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<nav { ...blockProps }>\n\t\t\t\t<ol ref={ disabledRef }>\n\t\t\t\t\t<TableOfContentsList nestedHeadingList={ headingTree } />\n\t\t\t\t</ol>\n\t\t\t</nav>\n\t\t\t{ toolbarControls }\n\t\t\t{ inspectorControls }\n\t\t</>\n\t);\n}\n"]}
@@ -4,6 +4,7 @@
4
4
  const metadata = {
5
5
  $schema: "https://schemas.wp.org/trunk/block.json",
6
6
  apiVersion: 2,
7
+ __experimental: true,
7
8
  name: "core/table-of-contents",
8
9
  title: "Table of Contents",
9
10
  category: "layout",
@@ -11,24 +12,32 @@ const metadata = {
11
12
  keywords: ["document outline", "summary"],
12
13
  textdomain: "default",
13
14
  attributes: {
15
+ headings: {
16
+ type: "array",
17
+ items: {
18
+ type: "object"
19
+ }
20
+ },
14
21
  onlyIncludeCurrentPage: {
15
22
  type: "boolean",
16
23
  "default": false
17
24
  }
18
25
  },
19
- usesContext: ["postId"],
20
26
  supports: {
21
27
  html: false
22
- }
28
+ },
29
+ example: {}
23
30
  };
24
31
  import edit from './edit';
25
32
  import icon from './icon';
33
+ import save from './save';
26
34
  const {
27
35
  name
28
36
  } = metadata;
29
37
  export { metadata, name };
30
38
  export const settings = {
31
39
  icon,
32
- edit
40
+ edit,
41
+ save
33
42
  };
34
43
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-library/src/table-of-contents/index.js"],"names":["edit","icon","name","metadata","settings"],"mappings":"AAAA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;AAEA,OAAOA,IAAP,MAAiB,QAAjB;AACA,OAAOC,IAAP,MAAiB,QAAjB;AAEA,MAAM;AAAEC,EAAAA;AAAF,IAAWC,QAAjB;AAEA,SAASA,QAAT,EAAmBD,IAAnB;AAEA,OAAO,MAAME,QAAQ,GAAG;AACvBH,EAAAA,IADuB;AAEvBD,EAAAA;AAFuB,CAAjB","sourcesContent":["/**\n * Internal dependencies\n */\nimport metadata from './block.json';\nimport edit from './edit';\nimport icon from './icon';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n};\n"]}
1
+ {"version":3,"sources":["@wordpress/block-library/src/table-of-contents/index.js"],"names":["edit","icon","save","name","metadata","settings"],"mappings":"AAAA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,OAAOA,IAAP,MAAiB,QAAjB;AACA,OAAOC,IAAP,MAAiB,QAAjB;AACA,OAAOC,IAAP,MAAiB,QAAjB;AAEA,MAAM;AAAEC,EAAAA;AAAF,IAAWC,QAAjB;AAEA,SAASA,QAAT,EAAmBD,IAAnB;AAEA,OAAO,MAAME,QAAQ,GAAG;AACvBJ,EAAAA,IADuB;AAEvBD,EAAAA,IAFuB;AAGvBE,EAAAA;AAHuB,CAAjB","sourcesContent":["/**\n * Internal dependencies\n */\nimport metadata from './block.json';\nimport edit from './edit';\nimport icon from './icon';\nimport save from './save';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\tsave,\n};\n"]}
@@ -1,25 +1,33 @@
1
- import { createElement } from "@wordpress/element";
1
+ import { createElement, Fragment } from "@wordpress/element";
2
+
3
+ /**
4
+ * WordPress dependencies
5
+ */
6
+
7
+ /**
8
+ * Internal dependencies
9
+ */
2
10
  const ENTRY_CLASS_NAME = 'wp-block-table-of-contents__entry';
3
11
  export default function TableOfContentsList(_ref) {
4
12
  let {
5
13
  nestedHeadingList
6
14
  } = _ref;
7
- return nestedHeadingList.map((childNode, index) => {
15
+ return createElement(Fragment, null, nestedHeadingList.map((node, index) => {
8
16
  const {
9
- anchor,
10
- content
11
- } = childNode.heading;
12
- const entry = anchor ? createElement("a", {
17
+ content,
18
+ link
19
+ } = node.heading;
20
+ const entry = link ? createElement("a", {
13
21
  className: ENTRY_CLASS_NAME,
14
- href: anchor
22
+ href: link
15
23
  }, content) : createElement("span", {
16
24
  className: ENTRY_CLASS_NAME
17
25
  }, content);
18
26
  return createElement("li", {
19
27
  key: index
20
- }, entry, childNode.children ? createElement("ul", null, createElement(TableOfContentsList, {
21
- nestedHeadingList: childNode.children
28
+ }, entry, node.children ? createElement("ol", null, createElement(TableOfContentsList, {
29
+ nestedHeadingList: node.children
22
30
  })) : null);
23
- });
31
+ }));
24
32
  }
25
33
  //# sourceMappingURL=list.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-library/src/table-of-contents/list.js"],"names":["ENTRY_CLASS_NAME","TableOfContentsList","nestedHeadingList","map","childNode","index","anchor","content","heading","entry","children"],"mappings":";AAAA,MAAMA,gBAAgB,GAAG,mCAAzB;AAEA,eAAe,SAASC,mBAAT,OAAsD;AAAA,MAAxB;AAAEC,IAAAA;AAAF,GAAwB;AACpE,SAAOA,iBAAiB,CAACC,GAAlB,CAAuB,CAAEC,SAAF,EAAaC,KAAb,KAAwB;AACrD,UAAM;AAAEC,MAAAA,MAAF;AAAUC,MAAAA;AAAV,QAAsBH,SAAS,CAACI,OAAtC;AAEA,UAAMC,KAAK,GAAGH,MAAM,GACnB;AAAG,MAAA,SAAS,EAAGN,gBAAf;AAAkC,MAAA,IAAI,EAAGM;AAAzC,OACGC,OADH,CADmB,GAKnB;AAAM,MAAA,SAAS,EAAGP;AAAlB,OAAuCO,OAAvC,CALD;AAQA,WACC;AAAI,MAAA,GAAG,EAAGF;AAAV,OACGI,KADH,EAEGL,SAAS,CAACM,QAAV,GACD,0BACC,cAAC,mBAAD;AACC,MAAA,iBAAiB,EAAGN,SAAS,CAACM;AAD/B,MADD,CADC,GAME,IARL,CADD;AAYA,GAvBM,CAAP;AAwBA","sourcesContent":["const ENTRY_CLASS_NAME = 'wp-block-table-of-contents__entry';\n\nexport default function TableOfContentsList( { nestedHeadingList } ) {\n\treturn nestedHeadingList.map( ( childNode, index ) => {\n\t\tconst { anchor, content } = childNode.heading;\n\n\t\tconst entry = anchor ? (\n\t\t\t<a className={ ENTRY_CLASS_NAME } href={ anchor }>\n\t\t\t\t{ content }\n\t\t\t</a>\n\t\t) : (\n\t\t\t<span className={ ENTRY_CLASS_NAME }>{ content }</span>\n\t\t);\n\n\t\treturn (\n\t\t\t<li key={ index }>\n\t\t\t\t{ entry }\n\t\t\t\t{ childNode.children ? (\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t<TableOfContentsList\n\t\t\t\t\t\t\tnestedHeadingList={ childNode.children }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ul>\n\t\t\t\t) : null }\n\t\t\t</li>\n\t\t);\n\t} );\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-library/src/table-of-contents/list.tsx"],"names":["ENTRY_CLASS_NAME","TableOfContentsList","nestedHeadingList","map","node","index","content","link","heading","entry","children"],"mappings":";;AAAA;AACA;AACA;;AAGA;AACA;AACA;AAGA,MAAMA,gBAAgB,GAAG,mCAAzB;AAEA,eAAe,SAASC,mBAAT,OAIA;AAAA,MAJ8B;AAC5CC,IAAAA;AAD4C,GAI9B;AACd,SACC,8BACGA,iBAAiB,CAACC,GAAlB,CAAuB,CAAEC,IAAF,EAAQC,KAAR,KAAmB;AAC3C,UAAM;AAAEC,MAAAA,OAAF;AAAWC,MAAAA;AAAX,QAAoBH,IAAI,CAACI,OAA/B;AAEA,UAAMC,KAAK,GAAGF,IAAI,GACjB;AAAG,MAAA,SAAS,EAAGP,gBAAf;AAAkC,MAAA,IAAI,EAAGO;AAAzC,OACGD,OADH,CADiB,GAKjB;AAAM,MAAA,SAAS,EAAGN;AAAlB,OAAuCM,OAAvC,CALD;AAQA,WACC;AAAI,MAAA,GAAG,EAAGD;AAAV,OACGI,KADH,EAEGL,IAAI,CAACM,QAAL,GACD,0BACC,cAAC,mBAAD;AACC,MAAA,iBAAiB,EAAGN,IAAI,CAACM;AAD1B,MADD,CADC,GAME,IARL,CADD;AAYA,GAvBC,CADH,CADD;AA4BA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport type { WPElement } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { NestedHeadingData } from './utils';\n\nconst ENTRY_CLASS_NAME = 'wp-block-table-of-contents__entry';\n\nexport default function TableOfContentsList( {\n\tnestedHeadingList,\n}: {\n\tnestedHeadingList: NestedHeadingData[];\n} ): WPElement {\n\treturn (\n\t\t<>\n\t\t\t{ nestedHeadingList.map( ( node, index ) => {\n\t\t\t\tconst { content, link } = node.heading;\n\n\t\t\t\tconst entry = link ? (\n\t\t\t\t\t<a className={ ENTRY_CLASS_NAME } href={ link }>\n\t\t\t\t\t\t{ content }\n\t\t\t\t\t</a>\n\t\t\t\t) : (\n\t\t\t\t\t<span className={ ENTRY_CLASS_NAME }>{ content }</span>\n\t\t\t\t);\n\n\t\t\t\treturn (\n\t\t\t\t\t<li key={ index }>\n\t\t\t\t\t\t{ entry }\n\t\t\t\t\t\t{ node.children ? (\n\t\t\t\t\t\t\t<ol>\n\t\t\t\t\t\t\t\t<TableOfContentsList\n\t\t\t\t\t\t\t\t\tnestedHeadingList={ node.children }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</ol>\n\t\t\t\t\t\t) : null }\n\t\t\t\t\t</li>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</>\n\t);\n}\n"]}
@@ -0,0 +1,28 @@
1
+ import { createElement } from "@wordpress/element";
2
+
3
+ /**
4
+ * WordPress dependencies
5
+ */
6
+ import { useBlockProps } from '@wordpress/block-editor';
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+
11
+ import TableOfContentsList from './list';
12
+ import { linearToNestedHeadingList } from './utils';
13
+ export default function save(_ref) {
14
+ let {
15
+ attributes: {
16
+ headings = []
17
+ }
18
+ } = _ref;
19
+
20
+ if (headings.length === 0) {
21
+ return null;
22
+ }
23
+
24
+ return createElement("nav", useBlockProps.save(), createElement("ol", null, createElement(TableOfContentsList, {
25
+ nestedHeadingList: linearToNestedHeadingList(headings)
26
+ })));
27
+ }
28
+ //# sourceMappingURL=save.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/block-library/src/table-of-contents/save.js"],"names":["useBlockProps","TableOfContentsList","linearToNestedHeadingList","save","attributes","headings","length"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,aAAT,QAA8B,yBAA9B;AAEA;AACA;AACA;;AACA,OAAOC,mBAAP,MAAgC,QAAhC;AACA,SAASC,yBAAT,QAA0C,SAA1C;AAEA,eAAe,SAASC,IAAT,OAAmD;AAAA,MAApC;AAAEC,IAAAA,UAAU,EAAE;AAAEC,MAAAA,QAAQ,GAAG;AAAb;AAAd,GAAoC;;AACjE,MAAKA,QAAQ,CAACC,MAAT,KAAoB,CAAzB,EAA6B;AAC5B,WAAO,IAAP;AACA;;AACD,SACC,qBAAUN,aAAa,CAACG,IAAd,EAAV,EACC,0BACC,cAAC,mBAAD;AACC,IAAA,iBAAiB,EAAGD,yBAAyB,CAAEG,QAAF;AAD9C,IADD,CADD,CADD;AASA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useBlockProps } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport TableOfContentsList from './list';\nimport { linearToNestedHeadingList } from './utils';\n\nexport default function save( { attributes: { headings = [] } } ) {\n\tif ( headings.length === 0 ) {\n\t\treturn null;\n\t}\n\treturn (\n\t\t<nav { ...useBlockProps.save() }>\n\t\t\t<ol>\n\t\t\t\t<TableOfContentsList\n\t\t\t\t\tnestedHeadingList={ linearToNestedHeadingList( headings ) }\n\t\t\t\t/>\n\t\t\t</ol>\n\t\t</nav>\n\t);\n}\n"]}
@@ -1,75 +1,12 @@
1
- /**
2
- * @typedef WPHeadingData
3
- *
4
- * @property {string} anchor The anchor link to the heading, or '' if none.
5
- * @property {string} content The plain text content of the heading.
6
- * @property {number} level The heading level.
7
- */
8
-
9
- /**
10
- * Extracts text, anchor, and level from a list of heading elements.
11
- *
12
- * @param {NodeList} headingElements The list of heading elements.
13
- *
14
- * @return {WPHeadingData[]} The list of heading parameters.
15
- */
16
- export function getHeadingsFromHeadingElements(headingElements) {
17
- return [...headingElements].map(heading => ({
18
- // A little hacky, but since we know at this point that the tag will
19
- // be an H1-H6, we can just grab the 2nd character of the tag name and
20
- // convert it to an integer. Should be faster than conditionals.
21
- level: parseInt(heading.tagName[1], 10),
22
- anchor: heading.hasAttribute('id') ? `#${heading.id}` : '',
23
- content: heading.textContent
24
- }));
25
- }
26
- /**
27
- * Extracts heading data from the provided content.
28
- *
29
- * @param {string} content The content to extract heading data from.
30
- *
31
- * @return {WPHeadingData[]} The list of heading parameters.
32
- */
33
-
34
- export function getHeadingsFromContent(content) {
35
- // Create a temporary container to put the post content into, so we can
36
- // use the DOM to find all the headings.
37
- const tempPostContentDOM = document.createElement('div');
38
- tempPostContentDOM.innerHTML = content; // Remove template elements so that headings inside them aren't counted.
39
- // This is only needed for IE11, which doesn't recognize the element and
40
- // treats it like a div.
41
-
42
- for (const template of tempPostContentDOM.querySelectorAll('template')) {
43
- template.remove();
44
- }
45
-
46
- const headingElements = tempPostContentDOM.querySelectorAll('h1:not(:empty), h2:not(:empty), h3:not(:empty), h4:not(:empty), h5:not(:empty), h6:not(:empty)');
47
- return getHeadingsFromHeadingElements(headingElements);
48
- }
49
- /**
50
- * @typedef WPNestedHeadingData
51
- *
52
- * @property {WPHeadingData} heading The heading content, anchor,
53
- * and level.
54
- * @property {number} index The index of this heading
55
- * node in the entire nested
56
- * list of heading data.
57
- * @property {WPNestedHeadingData[]|null} children The sub-headings of this
58
- * heading, if any.
59
- */
60
-
61
1
  /**
62
2
  * Takes a flat list of heading parameters and nests them based on each header's
63
3
  * immediate parent's level.
64
4
  *
65
- * @param {WPHeadingData[]} headingList The flat list of headings to nest.
66
- * @param {number} index The current list index.
5
+ * @param headingList The flat list of headings to nest.
67
6
  *
68
- * @return {WPNestedHeadingData[]} The nested list of headings.
7
+ * @return The nested list of headings.
69
8
  */
70
-
71
9
  export function linearToNestedHeadingList(headingList) {
72
- let index = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
73
10
  const nestedHeadingList = [];
74
11
  headingList.forEach((heading, key) => {
75
12
  if (heading.content === '') {
@@ -78,13 +15,15 @@ export function linearToNestedHeadingList(headingList) {
78
15
 
79
16
 
80
17
  if (heading.level === headingList[0].level) {
18
+ var _headingList;
19
+
81
20
  // Check that the next iteration will return a value.
82
21
  // If it does and the next level is greater than the current level,
83
22
  // the next iteration becomes a child of the current iteration.
84
- if (headingList[key + 1] !== undefined && headingList[key + 1].level > heading.level) {
85
- // We need to calculate the last index before the next iteration that has the same level (siblings).
86
- // We then use this last index to slice the array for use in recursion.
87
- // This prevents duplicate nodes.
23
+ if (((_headingList = headingList[key + 1]) === null || _headingList === void 0 ? void 0 : _headingList.level) > heading.level) {
24
+ // We must calculate the last index before the next iteration that
25
+ // has the same level (siblings). We then use this index to slice
26
+ // the array for use in recursion. This prevents duplicate nodes.
88
27
  let endOfSlice = headingList.length;
89
28
 
90
29
  for (let i = key + 1; i < headingList.length; i++) {
@@ -92,19 +31,18 @@ export function linearToNestedHeadingList(headingList) {
92
31
  endOfSlice = i;
93
32
  break;
94
33
  }
95
- } // We found a child node: Push a new node onto the return array with children.
34
+ } // We found a child node: Push a new node onto the return array
35
+ // with children.
96
36
 
97
37
 
98
38
  nestedHeadingList.push({
99
39
  heading,
100
- index: index + key,
101
- children: linearToNestedHeadingList(headingList.slice(key + 1, endOfSlice), index + key + 1)
40
+ children: linearToNestedHeadingList(headingList.slice(key + 1, endOfSlice))
102
41
  });
103
42
  } else {
104
43
  // No child node: Push a new node onto the return array.
105
44
  nestedHeadingList.push({
106
45
  heading,
107
- index: index + key,
108
46
  children: null
109
47
  });
110
48
  }