@wordpress/block-library 7.5.0 → 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 (527) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +3 -2
  3. package/babel-plugin.js +154 -0
  4. package/build/audio/edit.js +1 -1
  5. package/build/audio/edit.js.map +1 -1
  6. package/build/block/edit.js +10 -9
  7. package/build/block/edit.js.map +1 -1
  8. package/build/button/index.js +1 -0
  9. package/build/button/index.js.map +1 -1
  10. package/build/categories/edit.js +1 -1
  11. package/build/categories/edit.js.map +1 -1
  12. package/build/categories/index.js +1 -1
  13. package/build/comment-author-avatar/index.js +1 -0
  14. package/build/comment-author-avatar/index.js.map +1 -1
  15. package/build/comments-title/deprecated.js +110 -0
  16. package/build/comments-title/deprecated.js.map +1 -0
  17. package/build/comments-title/edit.js +35 -37
  18. package/build/comments-title/edit.js.map +1 -1
  19. package/build/comments-title/index.js +5 -8
  20. package/build/comments-title/index.js.map +1 -1
  21. package/build/cover/controls.native.js +2 -3
  22. package/build/cover/controls.native.js.map +1 -1
  23. package/build/cover/edit/block-controls.js +115 -0
  24. package/build/cover/edit/block-controls.js.map +1 -0
  25. package/build/cover/edit/cover-placeholder.js +49 -0
  26. package/build/cover/edit/cover-placeholder.js.map +1 -0
  27. package/build/cover/edit/index.js +333 -0
  28. package/build/cover/edit/index.js.map +1 -0
  29. package/build/cover/edit/inspector-controls.js +224 -0
  30. package/build/cover/edit/inspector-controls.js.map +1 -0
  31. package/build/cover/edit/resizable-cover.js +67 -0
  32. package/build/cover/edit/resizable-cover.js.map +1 -0
  33. package/build/cover/{use-cover-is-dark.js → edit/use-cover-is-dark.js} +0 -0
  34. package/build/cover/edit/use-cover-is-dark.js.map +1 -0
  35. package/build/cover/edit.native.js +0 -1
  36. package/build/cover/edit.native.js.map +1 -1
  37. package/build/cover/focal-point-settings-button.native.js.map +1 -1
  38. package/build/cover/shared.js +9 -0
  39. package/build/cover/shared.js.map +1 -1
  40. package/build/embed/embed-preview.js +1 -1
  41. package/build/embed/embed-preview.js.map +1 -1
  42. package/build/file/edit.native.js +0 -1
  43. package/build/file/edit.native.js.map +1 -1
  44. package/build/gallery/edit.js +2 -1
  45. package/build/gallery/edit.js.map +1 -1
  46. package/build/gallery/gallery.js +1 -1
  47. package/build/gallery/gallery.js.map +1 -1
  48. package/build/gallery/shared.js +2 -2
  49. package/build/gallery/shared.js.map +1 -1
  50. package/build/gallery/use-get-media.js +2 -1
  51. package/build/gallery/use-get-media.js.map +1 -1
  52. package/build/gallery/use-short-code-transform.js +19 -18
  53. package/build/gallery/use-short-code-transform.js.map +1 -1
  54. package/build/gallery/v1/gallery.js +1 -1
  55. package/build/gallery/v1/gallery.js.map +1 -1
  56. package/build/heading/edit.js +6 -2
  57. package/build/heading/edit.js.map +1 -1
  58. package/build/heading/index.js +1 -0
  59. package/build/heading/index.js.map +1 -1
  60. package/build/heading/transforms.js +1 -0
  61. package/build/heading/transforms.js.map +1 -1
  62. package/build/image/edit.js +5 -2
  63. package/build/image/edit.js.map +1 -1
  64. package/build/image/edit.native.js +0 -1
  65. package/build/image/edit.native.js.map +1 -1
  66. package/build/image/image.js +1 -1
  67. package/build/image/image.js.map +1 -1
  68. package/build/index.js +46 -10
  69. package/build/index.js.map +1 -1
  70. package/build/is-block-metadata-experimental.js +18 -0
  71. package/build/is-block-metadata-experimental.js.map +1 -0
  72. package/build/latest-posts/edit.js +30 -4
  73. package/build/latest-posts/edit.js.map +1 -1
  74. package/build/list/transforms.js +6 -0
  75. package/build/list/transforms.js.map +1 -1
  76. package/build/list/v2/edit.js +2 -1
  77. package/build/list/v2/edit.js.map +1 -1
  78. package/build/list/v2/migrate.js +1 -0
  79. package/build/list/v2/migrate.js.map +1 -1
  80. package/build/list/v2/transforms.js +46 -9
  81. package/build/list/v2/transforms.js.map +1 -1
  82. package/build/list-item/edit.js +7 -9
  83. package/build/list-item/edit.js.map +1 -1
  84. package/build/list-item/hooks/index.js +24 -0
  85. package/build/list-item/hooks/index.js.map +1 -1
  86. package/build/list-item/hooks/use-backspace.js +59 -0
  87. package/build/list-item/hooks/use-backspace.js.map +1 -0
  88. package/build/list-item/hooks/use-enter.js +6 -9
  89. package/build/list-item/hooks/use-enter.js.map +1 -1
  90. package/build/list-item/hooks/use-indent-list-item.js +33 -39
  91. package/build/list-item/hooks/use-indent-list-item.js.map +1 -1
  92. package/build/list-item/hooks/use-space.js +54 -0
  93. package/build/list-item/hooks/use-space.js.map +1 -0
  94. package/build/list-item/hooks/use-split.js +30 -0
  95. package/build/list-item/hooks/use-split.js.map +1 -0
  96. package/build/list-item/index.js +1 -0
  97. package/build/list-item/index.js.map +1 -1
  98. package/build/list-item/utils.js +1 -1
  99. package/build/list-item/utils.js.map +1 -1
  100. package/build/media-text/edit.native.js +2 -1
  101. package/build/media-text/edit.native.js.map +1 -1
  102. package/build/media-text/media-container.native.js +2 -4
  103. package/build/media-text/media-container.native.js.map +1 -1
  104. package/build/media-text/transforms.js +137 -8
  105. package/build/media-text/transforms.js.map +1 -1
  106. package/build/navigation/edit/index.js +86 -81
  107. package/build/navigation/edit/index.js.map +1 -1
  108. package/build/navigation/edit/inner-blocks.js +1 -5
  109. package/build/navigation/edit/inner-blocks.js.map +1 -1
  110. package/build/navigation/use-navigation-entities.js +3 -3
  111. package/build/navigation/use-navigation-entities.js.map +1 -1
  112. package/build/navigation-link/fallback-variations.js +1 -1
  113. package/build/navigation-link/fallback-variations.js.map +1 -1
  114. package/build/navigation-link/hooks.js +1 -1
  115. package/build/navigation-link/hooks.js.map +1 -1
  116. package/build/page-list/convert-to-links-modal.js +1 -1
  117. package/build/page-list/convert-to-links-modal.js.map +1 -1
  118. package/build/page-list/edit.js +1 -1
  119. package/build/page-list/edit.js.map +1 -1
  120. package/build/post-author/edit.js +1 -1
  121. package/build/post-author/edit.js.map +1 -1
  122. package/build/post-author-name/index.js +1 -0
  123. package/build/post-author-name/index.js.map +1 -1
  124. package/build/post-comment/index.js +1 -0
  125. package/build/post-comment/index.js.map +1 -1
  126. package/build/post-comments/edit.js +34 -16
  127. package/build/post-comments/edit.js.map +1 -1
  128. package/build/post-comments-count/index.js +1 -0
  129. package/build/post-comments-count/index.js.map +1 -1
  130. package/build/post-comments-form/form.js +1 -1
  131. package/build/post-comments-form/form.js.map +1 -1
  132. package/build/post-comments-link/index.js +1 -0
  133. package/build/post-comments-link/index.js.map +1 -1
  134. package/build/post-featured-image/edit.js +1 -1
  135. package/build/post-featured-image/edit.js.map +1 -1
  136. package/build/post-template/edit.js +7 -2
  137. package/build/post-template/edit.js.map +1 -1
  138. package/build/post-terms/edit.js +11 -2
  139. package/build/post-terms/edit.js.map +1 -1
  140. package/build/post-terms/hooks.js +33 -0
  141. package/build/post-terms/hooks.js.map +1 -0
  142. package/build/post-terms/index.js +12 -5
  143. package/build/post-terms/index.js.map +1 -1
  144. package/build/post-title/index.js +1 -1
  145. package/build/post-title/index.js.map +1 -1
  146. package/build/pullquote/edit.js +1 -1
  147. package/build/pullquote/edit.js.map +1 -1
  148. package/build/pullquote/edit.native.js +1 -1
  149. package/build/pullquote/edit.native.js.map +1 -1
  150. package/build/query/edit/inspector-controls/index.js +26 -17
  151. package/build/query/edit/inspector-controls/index.js.map +1 -1
  152. package/build/query/edit/inspector-controls/parent-control.js +148 -0
  153. package/build/query/edit/inspector-controls/parent-control.js.map +1 -0
  154. package/build/query/edit/inspector-controls/sticky-control.js +41 -0
  155. package/build/query/edit/inspector-controls/sticky-control.js.map +1 -0
  156. package/build/query/index.js +2 -1
  157. package/build/query/index.js.map +1 -1
  158. package/build/query/utils.js +28 -2
  159. package/build/query/utils.js.map +1 -1
  160. package/build/query-title/index.js +1 -1
  161. package/build/query-title/index.js.map +1 -1
  162. package/build/query-title/variations.js +1 -1
  163. package/build/query-title/variations.js.map +1 -1
  164. package/build/quote/edit.js +3 -2
  165. package/build/quote/edit.js.map +1 -1
  166. package/build/quote/v2/edit.js +1 -1
  167. package/build/quote/v2/edit.js.map +1 -1
  168. package/build/search/edit.js +1 -0
  169. package/build/search/edit.js.map +1 -1
  170. package/build/site-logo/edit.js +1 -1
  171. package/build/site-logo/edit.js.map +1 -1
  172. package/build/table/edit.js +15 -2
  173. package/build/table/edit.js.map +1 -1
  174. package/build/table-of-contents/edit.js +138 -66
  175. package/build/table-of-contents/edit.js.map +1 -1
  176. package/build/table-of-contents/index.js +13 -3
  177. package/build/table-of-contents/index.js.map +1 -1
  178. package/build/table-of-contents/list.js +16 -9
  179. package/build/table-of-contents/list.js.map +1 -1
  180. package/build/table-of-contents/save.js +40 -0
  181. package/build/table-of-contents/save.js.map +1 -0
  182. package/build/table-of-contents/utils.js +11 -77
  183. package/build/table-of-contents/utils.js.map +1 -1
  184. package/build/template-part/edit/index.js +7 -3
  185. package/build/template-part/edit/index.js.map +1 -1
  186. package/build/template-part/edit/inner-blocks.js +3 -8
  187. package/build/template-part/edit/inner-blocks.js.map +1 -1
  188. package/build/video/edit.js +1 -1
  189. package/build/video/edit.js.map +1 -1
  190. package/build-module/audio/edit.js +2 -2
  191. package/build-module/audio/edit.js.map +1 -1
  192. package/build-module/block/edit.js +11 -10
  193. package/build-module/block/edit.js.map +1 -1
  194. package/build-module/button/index.js +1 -0
  195. package/build-module/button/index.js.map +1 -1
  196. package/build-module/categories/edit.js +1 -1
  197. package/build-module/categories/edit.js.map +1 -1
  198. package/build-module/categories/index.js +1 -1
  199. package/build-module/comment-author-avatar/index.js +1 -0
  200. package/build-module/comment-author-avatar/index.js.map +1 -1
  201. package/build-module/comments-title/deprecated.js +102 -0
  202. package/build-module/comments-title/deprecated.js.map +1 -0
  203. package/build-module/comments-title/edit.js +38 -40
  204. package/build-module/comments-title/edit.js.map +1 -1
  205. package/build-module/comments-title/index.js +4 -8
  206. package/build-module/comments-title/index.js.map +1 -1
  207. package/build-module/cover/controls.native.js +2 -3
  208. package/build-module/cover/controls.native.js.map +1 -1
  209. package/build-module/cover/edit/block-controls.js +104 -0
  210. package/build-module/cover/edit/block-controls.js.map +1 -0
  211. package/build-module/cover/edit/cover-placeholder.js +38 -0
  212. package/build-module/cover/edit/cover-placeholder.js.map +1 -0
  213. package/build-module/cover/edit/index.js +307 -0
  214. package/build-module/cover/edit/index.js.map +1 -0
  215. package/build-module/cover/edit/inspector-controls.js +215 -0
  216. package/build-module/cover/edit/inspector-controls.js.map +1 -0
  217. package/build-module/cover/edit/resizable-cover.js +55 -0
  218. package/build-module/cover/edit/resizable-cover.js.map +1 -0
  219. package/build-module/cover/{use-cover-is-dark.js → edit/use-cover-is-dark.js} +0 -0
  220. package/build-module/cover/edit/use-cover-is-dark.js.map +1 -0
  221. package/build-module/cover/edit.native.js +0 -1
  222. package/build-module/cover/edit.native.js.map +1 -1
  223. package/build-module/cover/focal-point-settings-button.native.js.map +1 -1
  224. package/build-module/cover/shared.js +7 -0
  225. package/build-module/cover/shared.js.map +1 -1
  226. package/build-module/embed/embed-preview.js +2 -2
  227. package/build-module/embed/embed-preview.js.map +1 -1
  228. package/build-module/file/edit.native.js +0 -1
  229. package/build-module/file/edit.native.js.map +1 -1
  230. package/build-module/gallery/edit.js +2 -1
  231. package/build-module/gallery/edit.js.map +1 -1
  232. package/build-module/gallery/gallery.js +2 -2
  233. package/build-module/gallery/gallery.js.map +1 -1
  234. package/build-module/gallery/shared.js +2 -2
  235. package/build-module/gallery/shared.js.map +1 -1
  236. package/build-module/gallery/use-get-media.js +2 -1
  237. package/build-module/gallery/use-get-media.js.map +1 -1
  238. package/build-module/gallery/use-short-code-transform.js +19 -18
  239. package/build-module/gallery/use-short-code-transform.js.map +1 -1
  240. package/build-module/gallery/v1/gallery.js +2 -2
  241. package/build-module/gallery/v1/gallery.js.map +1 -1
  242. package/build-module/heading/edit.js +6 -2
  243. package/build-module/heading/edit.js.map +1 -1
  244. package/build-module/heading/index.js +1 -0
  245. package/build-module/heading/index.js.map +1 -1
  246. package/build-module/heading/transforms.js +1 -0
  247. package/build-module/heading/transforms.js.map +1 -1
  248. package/build-module/image/edit.js +6 -3
  249. package/build-module/image/edit.js.map +1 -1
  250. package/build-module/image/edit.native.js +0 -1
  251. package/build-module/image/edit.native.js.map +1 -1
  252. package/build-module/image/image.js +2 -2
  253. package/build-module/image/image.js.map +1 -1
  254. package/build-module/index.js +42 -10
  255. package/build-module/index.js.map +1 -1
  256. package/build-module/is-block-metadata-experimental.js +16 -0
  257. package/build-module/is-block-metadata-experimental.js.map +1 -0
  258. package/build-module/latest-posts/edit.js +29 -5
  259. package/build-module/latest-posts/edit.js.map +1 -1
  260. package/build-module/list/transforms.js +6 -0
  261. package/build-module/list/transforms.js.map +1 -1
  262. package/build-module/list/v2/edit.js +2 -1
  263. package/build-module/list/v2/edit.js.map +1 -1
  264. package/build-module/list/v2/migrate.js +1 -3
  265. package/build-module/list/v2/migrate.js.map +1 -1
  266. package/build-module/list/v2/transforms.js +46 -9
  267. package/build-module/list/v2/transforms.js.map +1 -1
  268. package/build-module/list-item/edit.js +8 -9
  269. package/build-module/list-item/edit.js.map +1 -1
  270. package/build-module/list-item/hooks/index.js +3 -0
  271. package/build-module/list-item/hooks/index.js.map +1 -1
  272. package/build-module/list-item/hooks/use-backspace.js +44 -0
  273. package/build-module/list-item/hooks/use-backspace.js.map +1 -0
  274. package/build-module/list-item/hooks/use-enter.js +6 -9
  275. package/build-module/list-item/hooks/use-enter.js.map +1 -1
  276. package/build-module/list-item/hooks/use-indent-list-item.js +33 -38
  277. package/build-module/list-item/hooks/use-indent-list-item.js.map +1 -1
  278. package/build-module/list-item/hooks/use-space.js +40 -0
  279. package/build-module/list-item/hooks/use-space.js.map +1 -0
  280. package/build-module/list-item/hooks/use-split.js +19 -0
  281. package/build-module/list-item/hooks/use-split.js.map +1 -0
  282. package/build-module/list-item/index.js +1 -0
  283. package/build-module/list-item/index.js.map +1 -1
  284. package/build-module/list-item/utils.js +1 -1
  285. package/build-module/list-item/utils.js.map +1 -1
  286. package/build-module/media-text/edit.native.js +2 -1
  287. package/build-module/media-text/edit.native.js.map +1 -1
  288. package/build-module/media-text/media-container.native.js +2 -4
  289. package/build-module/media-text/media-container.native.js.map +1 -1
  290. package/build-module/media-text/transforms.js +137 -8
  291. package/build-module/media-text/transforms.js.map +1 -1
  292. package/build-module/navigation/edit/index.js +87 -82
  293. package/build-module/navigation/edit/index.js.map +1 -1
  294. package/build-module/navigation/edit/inner-blocks.js +2 -6
  295. package/build-module/navigation/edit/inner-blocks.js.map +1 -1
  296. package/build-module/navigation/use-navigation-entities.js +1 -1
  297. package/build-module/navigation/use-navigation-entities.js.map +1 -1
  298. package/build-module/navigation-link/fallback-variations.js +1 -1
  299. package/build-module/navigation-link/fallback-variations.js.map +1 -1
  300. package/build-module/navigation-link/hooks.js +2 -2
  301. package/build-module/navigation-link/hooks.js.map +1 -1
  302. package/build-module/page-list/convert-to-links-modal.js +1 -1
  303. package/build-module/page-list/convert-to-links-modal.js.map +1 -1
  304. package/build-module/page-list/edit.js +1 -1
  305. package/build-module/page-list/edit.js.map +1 -1
  306. package/build-module/post-author/edit.js +1 -1
  307. package/build-module/post-author/edit.js.map +1 -1
  308. package/build-module/post-author-name/index.js +1 -0
  309. package/build-module/post-author-name/index.js.map +1 -1
  310. package/build-module/post-comment/index.js +1 -0
  311. package/build-module/post-comment/index.js.map +1 -1
  312. package/build-module/post-comments/edit.js +35 -16
  313. package/build-module/post-comments/edit.js.map +1 -1
  314. package/build-module/post-comments-count/index.js +1 -0
  315. package/build-module/post-comments-count/index.js.map +1 -1
  316. package/build-module/post-comments-form/form.js +1 -1
  317. package/build-module/post-comments-form/form.js.map +1 -1
  318. package/build-module/post-comments-link/index.js +1 -0
  319. package/build-module/post-comments-link/index.js.map +1 -1
  320. package/build-module/post-featured-image/edit.js +1 -1
  321. package/build-module/post-featured-image/edit.js.map +1 -1
  322. package/build-module/post-template/edit.js +7 -2
  323. package/build-module/post-template/edit.js.map +1 -1
  324. package/build-module/post-terms/edit.js +10 -3
  325. package/build-module/post-terms/edit.js.map +1 -1
  326. package/build-module/post-terms/hooks.js +25 -0
  327. package/build-module/post-terms/hooks.js.map +1 -0
  328. package/build-module/post-terms/index.js +10 -8
  329. package/build-module/post-terms/index.js.map +1 -1
  330. package/build-module/post-title/index.js +1 -1
  331. package/build-module/post-title/index.js.map +1 -1
  332. package/build-module/pullquote/edit.js +2 -2
  333. package/build-module/pullquote/edit.js.map +1 -1
  334. package/build-module/pullquote/edit.native.js +2 -2
  335. package/build-module/pullquote/edit.native.js.map +1 -1
  336. package/build-module/query/edit/inspector-controls/index.js +24 -17
  337. package/build-module/query/edit/inspector-controls/index.js.map +1 -1
  338. package/build-module/query/edit/inspector-controls/parent-control.js +135 -0
  339. package/build-module/query/edit/inspector-controls/parent-control.js.map +1 -0
  340. package/build-module/query/edit/inspector-controls/sticky-control.js +31 -0
  341. package/build-module/query/edit/inspector-controls/sticky-control.js.map +1 -0
  342. package/build-module/query/index.js +2 -1
  343. package/build-module/query/index.js.map +1 -1
  344. package/build-module/query/utils.js +21 -0
  345. package/build-module/query/utils.js.map +1 -1
  346. package/build-module/query-title/index.js +1 -1
  347. package/build-module/query-title/index.js.map +1 -1
  348. package/build-module/query-title/variations.js +2 -2
  349. package/build-module/query-title/variations.js.map +1 -1
  350. package/build-module/quote/edit.js +4 -3
  351. package/build-module/quote/edit.js.map +1 -1
  352. package/build-module/quote/v2/edit.js +2 -2
  353. package/build-module/quote/v2/edit.js.map +1 -1
  354. package/build-module/search/edit.js +1 -0
  355. package/build-module/search/edit.js.map +1 -1
  356. package/build-module/site-logo/edit.js +1 -1
  357. package/build-module/site-logo/edit.js.map +1 -1
  358. package/build-module/table/edit.js +17 -4
  359. package/build-module/table/edit.js.map +1 -1
  360. package/build-module/table-of-contents/edit.js +136 -68
  361. package/build-module/table-of-contents/edit.js.map +1 -1
  362. package/build-module/table-of-contents/index.js +12 -3
  363. package/build-module/table-of-contents/index.js.map +1 -1
  364. package/build-module/table-of-contents/list.js +18 -10
  365. package/build-module/table-of-contents/list.js.map +1 -1
  366. package/build-module/table-of-contents/save.js +28 -0
  367. package/build-module/table-of-contents/save.js.map +1 -0
  368. package/build-module/table-of-contents/utils.js +11 -73
  369. package/build-module/table-of-contents/utils.js.map +1 -1
  370. package/build-module/template-part/edit/index.js +8 -4
  371. package/build-module/template-part/edit/index.js.map +1 -1
  372. package/build-module/template-part/edit/inner-blocks.js +4 -9
  373. package/build-module/template-part/edit/inner-blocks.js.map +1 -1
  374. package/build-module/video/edit.js +2 -2
  375. package/build-module/video/edit.js.map +1 -1
  376. package/build-style/editor-rtl.css +4 -6
  377. package/build-style/editor.css +4 -6
  378. package/build-style/image/editor-rtl.css +1 -1
  379. package/build-style/image/editor.css +1 -1
  380. package/build-style/post-comments/style-rtl.css +22 -0
  381. package/build-style/post-comments/style.css +22 -0
  382. package/build-style/post-comments-form/style-rtl.css +1 -3
  383. package/build-style/post-comments-form/style.css +1 -3
  384. package/build-style/separator/editor-rtl.css +1 -0
  385. package/build-style/separator/editor.css +1 -0
  386. package/build-style/style-rtl.css +23 -3
  387. package/build-style/style.css +23 -3
  388. package/build-style/video/editor-rtl.css +2 -5
  389. package/build-style/video/editor.css +2 -5
  390. package/build-types/table-of-contents/list.d.ts +12 -0
  391. package/build-types/table-of-contents/list.d.ts.map +1 -0
  392. package/build-types/table-of-contents/utils.d.ts +24 -0
  393. package/build-types/table-of-contents/utils.d.ts.map +1 -0
  394. package/package.json +30 -29
  395. package/src/audio/edit.js +4 -2
  396. package/src/avatar/block.json +0 -1
  397. package/src/avatar/index.php +2 -2
  398. package/src/block/edit.js +39 -42
  399. package/src/block/test/edit.native.js +1 -1
  400. package/src/button/block.json +1 -0
  401. package/src/categories/block.json +1 -1
  402. package/src/categories/edit.js +1 -1
  403. package/src/comment-author-avatar/block.json +1 -0
  404. package/src/comments-title/block.json +0 -6
  405. package/src/comments-title/deprecated.js +34 -0
  406. package/src/comments-title/edit.js +44 -100
  407. package/src/comments-title/index.js +3 -1
  408. package/src/comments-title/index.php +41 -23
  409. package/src/cover/controls.native.js +1 -2
  410. package/src/cover/edit/block-controls.js +119 -0
  411. package/src/cover/edit/cover-placeholder.js +39 -0
  412. package/src/cover/edit/index.js +381 -0
  413. package/src/cover/edit/inspector-controls.js +286 -0
  414. package/src/cover/edit/resizable-cover.js +55 -0
  415. package/src/cover/{use-cover-is-dark.js → edit/use-cover-is-dark.js} +0 -0
  416. package/src/cover/edit.native.js +0 -1
  417. package/src/cover/editor.scss +1 -1
  418. package/src/cover/focal-point-settings-button.native.js +1 -1
  419. package/src/cover/index.php +20 -37
  420. package/src/cover/shared.js +4 -0
  421. package/src/cover/test/block-controls.js +62 -0
  422. package/src/embed/embed-preview.js +4 -2
  423. package/src/file/edit.native.js +0 -1
  424. package/src/gallery/edit.js +2 -1
  425. package/src/gallery/gallery.js +2 -2
  426. package/src/gallery/shared.js +3 -2
  427. package/src/gallery/use-get-media.js +2 -1
  428. package/src/gallery/use-short-code-transform.js +19 -16
  429. package/src/gallery/v1/gallery.js +2 -2
  430. package/src/heading/block.json +1 -0
  431. package/src/heading/edit.js +5 -2
  432. package/src/image/edit.js +9 -1
  433. package/src/image/edit.native.js +0 -1
  434. package/src/image/editor.scss +1 -1
  435. package/src/image/image.js +8 -2
  436. package/src/image/test/edit.native.js +7 -7
  437. package/src/index.js +50 -27
  438. package/src/is-block-metadata-experimental.js +19 -0
  439. package/src/latest-posts/edit.js +27 -2
  440. package/src/latest-posts/index.php +12 -6
  441. package/src/list/transforms.js +7 -0
  442. package/src/list/v2/edit.js +1 -0
  443. package/src/list/v2/migrate.js +1 -1
  444. package/src/list/v2/transforms.js +35 -0
  445. package/src/list-item/block.json +2 -1
  446. package/src/list-item/edit.js +17 -10
  447. package/src/list-item/hooks/index.js +3 -0
  448. package/src/list-item/hooks/use-backspace.js +52 -0
  449. package/src/list-item/hooks/use-enter.js +9 -16
  450. package/src/list-item/hooks/use-indent-list-item.js +50 -63
  451. package/src/list-item/hooks/use-space.js +48 -0
  452. package/src/list-item/hooks/use-split.js +24 -0
  453. package/src/list-item/utils.js +1 -1
  454. package/src/media-text/edit.native.js +3 -1
  455. package/src/media-text/media-container.native.js +2 -4
  456. package/src/media-text/transforms.js +154 -0
  457. package/src/navigation/edit/index.js +175 -169
  458. package/src/navigation/edit/inner-blocks.js +1 -8
  459. package/src/navigation/index.php +40 -0
  460. package/src/navigation/use-navigation-entities.js +1 -1
  461. package/src/navigation-link/fallback-variations.js +1 -1
  462. package/src/navigation-link/hooks.js +2 -2
  463. package/src/navigation-link/test/__snapshots__/hooks.js.snap +4 -4
  464. package/src/page-list/convert-to-links-modal.js +1 -1
  465. package/src/page-list/edit.js +1 -4
  466. package/src/post-author/edit.js +24 -22
  467. package/src/post-author-name/block.json +1 -0
  468. package/src/post-comment/block.json +1 -0
  469. package/src/post-comments/edit.js +54 -22
  470. package/src/post-comments/style.scss +26 -0
  471. package/src/post-comments-count/block.json +1 -0
  472. package/src/post-comments-form/form.js +1 -4
  473. package/src/post-comments-form/style.scss +1 -4
  474. package/src/post-comments-link/block.json +1 -0
  475. package/src/post-featured-image/edit.js +1 -1
  476. package/src/post-template/edit.js +5 -0
  477. package/src/post-template/index.php +30 -0
  478. package/src/post-terms/edit.js +19 -0
  479. package/src/post-terms/hooks.js +27 -0
  480. package/src/post-terms/index.js +14 -7
  481. package/src/post-terms/index.php +40 -2
  482. package/src/post-title/index.js +1 -1
  483. package/src/pullquote/edit.js +2 -2
  484. package/src/pullquote/edit.native.js +2 -2
  485. package/src/query/block.json +2 -1
  486. package/src/query/edit/inspector-controls/index.js +25 -11
  487. package/src/query/edit/inspector-controls/parent-control.js +133 -0
  488. package/src/query/edit/inspector-controls/sticky-control.js +25 -0
  489. package/src/query/utils.js +22 -0
  490. package/src/query-title/index.js +1 -1
  491. package/src/query-title/variations.js +2 -2
  492. package/src/quote/edit.js +5 -2
  493. package/src/quote/v2/edit.js +4 -2
  494. package/src/search/edit.js +1 -0
  495. package/src/search/index.php +1 -1
  496. package/src/separator/editor.scss +1 -0
  497. package/src/site-logo/edit.js +1 -1
  498. package/src/table/edit.js +19 -4
  499. package/src/table-of-contents/block.json +9 -2
  500. package/src/table-of-contents/edit.js +155 -75
  501. package/src/table-of-contents/index.js +2 -0
  502. package/src/table-of-contents/list.tsx +46 -0
  503. package/src/table-of-contents/save.js +25 -0
  504. package/src/table-of-contents/utils.ts +71 -0
  505. package/src/tag-cloud/block.json +1 -1
  506. package/src/template-part/edit/index.js +25 -15
  507. package/src/template-part/edit/inner-blocks.js +2 -10
  508. package/src/video/edit.js +4 -2
  509. package/src/video/editor.scss +3 -6
  510. package/test/babel-plugin.js +67 -0
  511. package/tsconfig.json +11 -0
  512. package/tsconfig.tsbuildinfo +1 -0
  513. package/build/cover/edit.js +0 -598
  514. package/build/cover/edit.js.map +0 -1
  515. package/build/cover/use-cover-is-dark.js.map +0 -1
  516. package/build/post-terms/variations.js +0 -37
  517. package/build/post-terms/variations.js.map +0 -1
  518. package/build-module/cover/edit.js +0 -575
  519. package/build-module/cover/edit.js.map +0 -1
  520. package/build-module/cover/use-cover-is-dark.js.map +0 -1
  521. package/build-module/post-terms/variations.js +0 -27
  522. package/build-module/post-terms/variations.js.map +0 -1
  523. package/src/cover/edit.js +0 -757
  524. package/src/post-terms/variations.js +0 -28
  525. package/src/table-of-contents/index.php +0 -346
  526. package/src/table-of-contents/list.js +0 -28
  527. package/src/table-of-contents/utils.js +0 -126
@@ -17,10 +17,18 @@ var _blocks = require("@wordpress/blocks");
17
17
 
18
18
  var _components = require("@wordpress/components");
19
19
 
20
+ var _compose = require("@wordpress/compose");
21
+
20
22
  var _data = require("@wordpress/data");
21
23
 
24
+ var _dom = require("@wordpress/dom");
25
+
22
26
  var _i18n = require("@wordpress/i18n");
23
27
 
28
+ var _url = require("@wordpress/url");
29
+
30
+ var _icon = _interopRequireDefault(require("./icon"));
31
+
24
32
  var _list = _interopRequireDefault(require("./list"));
25
33
 
26
34
  var _utils = require("./utils");
@@ -37,14 +45,15 @@ var _utils = require("./utils");
37
45
  * Internal dependencies
38
46
  */
39
47
 
48
+ /** @typedef {import('./utils').HeadingData} HeadingData */
49
+
40
50
  /**
41
51
  * Table of Contents block edit component.
42
52
  *
43
53
  * @param {Object} props The props.
44
54
  * @param {Object} props.attributes The block attributes.
45
- * @param {boolean} props.attributes.onlyIncludeCurrentPage
46
- * Whether to only include headings from the current page (if the post is
47
- * paginated).
55
+ * @param {HeadingData[]} props.attributes.headings A list of data for each heading in the post.
56
+ * @param {boolean} props.attributes.onlyIncludeCurrentPage Whether to only include headings from the current page (if the post is paginated).
48
57
  * @param {string} props.clientId
49
58
  * @param {(attributes: Object) => void} props.setAttributes
50
59
  *
@@ -53,96 +62,157 @@ var _utils = require("./utils");
53
62
  function TableOfContentsEdit(_ref) {
54
63
  let {
55
64
  attributes: {
65
+ headings = [],
56
66
  onlyIncludeCurrentPage
57
67
  },
58
68
  clientId,
59
69
  setAttributes
60
70
  } = _ref;
61
- const blockProps = (0, _blockEditor.useBlockProps)(); // Local state; not saved to block attributes. The saved block is dynamic and uses PHP to generate its content.
62
-
63
- const [headings, setHeadings] = (0, _element.useState)([]);
64
- const [headingTree, setHeadingTree] = (0, _element.useState)([]);
71
+ const blockProps = (0, _blockEditor.useBlockProps)();
72
+ const disabledRef = (0, _compose.useDisabled)();
73
+ const listBlockExists = (0, _data.useSelect)(select => !!select(_blocks.store).getBlockType('core/list'), []);
65
74
  const {
66
- listBlockExists,
67
- postContent
68
- } = (0, _data.useSelect)(select => ({
69
- listBlockExists: !!select(_blocks.store).getBlockType('core/list'),
70
- // FIXME: @wordpress/block-library should not depend on @wordpress/editor.
71
- // Blocks can be loaded into a *non-post* block editor.
72
- // eslint-disable-next-line @wordpress/data-no-store-string-literals
73
- postContent: select('core/editor').getEditedPostContent()
74
- }), []); // The page this block would be part of on the front-end. For performance
75
- // reasons, this is only calculated when onlyIncludeCurrentPage is true.
76
-
77
- const pageIndex = (0, _data.useSelect)(select => {
78
- if (!onlyIncludeCurrentPage) {
79
- return null;
80
- }
75
+ __unstableMarkNextChangeAsNotPersistent,
76
+ replaceBlocks
77
+ } = (0, _data.useDispatch)(_blockEditor.store);
78
+ /**
79
+ * The latest heading data, or null if the new data deeply equals the saved
80
+ * headings attribute.
81
+ *
82
+ * Since useSelect forces a re-render when its return value is shallowly
83
+ * inequal to its prior call, we would be re-rendering this block every time
84
+ * the stores change, even if the latest headings were deeply equal to the
85
+ * ones saved in the block attributes.
86
+ *
87
+ * By returning null when they're equal, we reduce that to 2 renders: one
88
+ * when there are new latest headings (and so it returns them), and one when
89
+ * they haven't changed (so it returns null). As long as the latest heading
90
+ * data remains the same, further calls of the useSelect callback will
91
+ * continue to return null, thus preventing any forced re-renders.
92
+ */
93
+
94
+ const latestHeadings = (0, _data.useSelect)(select => {
95
+ var _editorSelectors$getP;
81
96
 
82
97
  const {
83
98
  getBlockAttributes,
84
- getBlockIndex,
85
99
  getBlockName,
86
- getBlockOrder
87
- } = select(_blockEditor.store);
88
- const blockIndex = getBlockIndex(clientId);
89
- const blockOrder = getBlockOrder(); // Calculate which page the block will appear in on the front-end by
90
- // counting how many <!--nextpage--> tags precede it.
91
- // Unfortunately, this implementation only accounts for Page Break and
92
- // Classic blocks, so if there are any <!--nextpage--> tags in any
93
- // other block, they won't be counted. This will result in the table
94
- // of contents showing headings from the wrong page if
95
- // onlyIncludeCurrentPage === true. Thankfully, this issue only
96
- // affects the editor implementation.
97
-
98
- let page = 1;
99
-
100
- for (let i = 0; i < blockIndex; i++) {
101
- const blockName = getBlockName(blockOrder[i]);
100
+ getClientIdsWithDescendants,
101
+ __experimentalGetGlobalBlocksByName: getGlobalBlocksByName
102
+ } = select(_blockEditor.store); // FIXME: @wordpress/block-library should not depend on @wordpress/editor.
103
+ // Blocks can be loaded into a *non-post* block editor, so to avoid
104
+ // declaring @wordpress/editor as a dependency, we must access its
105
+ // store by string. When the store is not available, editorSelectors
106
+ // will be null, and the block's saved markup will lack permalinks.
107
+ // eslint-disable-next-line @wordpress/data-no-store-string-literals
102
108
 
103
- if (blockName === 'core/nextpage') {
104
- page++;
105
- } else if (blockName === 'core/freeform') {
106
- var _getBlockAttributes$c;
109
+ const editorSelectors = select('core/editor');
110
+ const pageBreakClientIds = getGlobalBlocksByName('core/nextpage');
111
+ const isPaginated = pageBreakClientIds.length !== 0; // Get the client ids of all blocks in the editor.
112
+
113
+ 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.
107
114
 
108
- // Count the page breaks inside the Classic block.
109
- const pageBreaks = (_getBlockAttributes$c = getBlockAttributes(blockOrder[i]).content) === null || _getBlockAttributes$c === void 0 ? void 0 : _getBlockAttributes$c.match(/<!--nextpage-->/g);
115
+ let tocPage = 1;
110
116
 
111
- if (pageBreaks !== null && pageBreaks !== undefined) {
112
- page += pageBreaks.length;
117
+ if (isPaginated && onlyIncludeCurrentPage) {
118
+ // We can't use getBlockIndex because it only returns the index
119
+ // relative to sibling blocks.
120
+ const tocIndex = allBlockClientIds.indexOf(clientId);
121
+
122
+ for (const [blockIndex, blockClientId] of allBlockClientIds.entries()) {
123
+ // If we've reached blocks after the Table of Contents, we've
124
+ // finished calculating which page the block is on.
125
+ if (blockIndex >= tocIndex) {
126
+ break;
127
+ }
128
+
129
+ if (getBlockName(blockClientId) === 'core/nextpage') {
130
+ tocPage++;
113
131
  }
114
132
  }
115
133
  }
116
134
 
117
- return page;
118
- }, [clientId, onlyIncludeCurrentPage]);
119
- (0, _element.useEffect)(() => {
120
- let latestHeadings;
135
+ const _latestHeadings = [];
136
+ /** The page (of a paginated post) a heading will be part of. */
121
137
 
122
- if (onlyIncludeCurrentPage) {
123
- const pagesOfContent = postContent.split('<!--nextpage-->');
124
- latestHeadings = (0, _utils.getHeadingsFromContent)(pagesOfContent[pageIndex - 1]);
125
- } else {
126
- latestHeadings = (0, _utils.getHeadingsFromContent)(postContent);
138
+ let headingPage = 1;
139
+ /**
140
+ * A permalink to the current post. If the core/editor store is
141
+ * unavailable, this variable will be null.
142
+ */
143
+
144
+ const permalink = (_editorSelectors$getP = editorSelectors === null || editorSelectors === void 0 ? void 0 : editorSelectors.getPermalink()) !== null && _editorSelectors$getP !== void 0 ? _editorSelectors$getP : null;
145
+ let headingPageLink = null; // If the core/editor store is available, we can add permalinks to the
146
+ // generated table of contents.
147
+
148
+ if (typeof permalink === 'string') {
149
+ headingPageLink = isPaginated ? (0, _url.addQueryArgs)(permalink, {
150
+ page: headingPage
151
+ }) : permalink;
127
152
  }
128
153
 
129
- if (!(0, _lodash.isEqual)(headings, latestHeadings)) {
130
- setHeadings(latestHeadings);
131
- setHeadingTree((0, _utils.linearToNestedHeadingList)(latestHeadings));
154
+ for (const blockClientId of allBlockClientIds) {
155
+ const blockName = getBlockName(blockClientId);
156
+
157
+ if (blockName === 'core/nextpage') {
158
+ headingPage++; // If we're only including headings from the current page (of
159
+ // a paginated post), then exit the loop if we've reached the
160
+ // pages after the one with the Table of Contents block.
161
+
162
+ if (onlyIncludeCurrentPage && headingPage > tocPage) {
163
+ break;
164
+ }
165
+
166
+ if (typeof permalink === 'string') {
167
+ headingPageLink = (0, _url.addQueryArgs)((0, _url.removeQueryArgs)(permalink, ['page']), {
168
+ page: headingPage
169
+ });
170
+ }
171
+ } // If we're including all headings or we've reached headings on
172
+ // the same page as the Table of Contents block, add them to the
173
+ // list.
174
+ else if (!onlyIncludeCurrentPage || headingPage === tocPage) {
175
+ if (blockName === 'core/heading') {
176
+ const headingAttributes = getBlockAttributes(blockClientId);
177
+ const canBeLinked = typeof headingPageLink === 'string' && typeof headingAttributes.anchor === 'string' && headingAttributes.anchor !== '';
178
+
179
+ _latestHeadings.push({
180
+ content: (0, _dom.__unstableStripHTML)(headingAttributes.content),
181
+ level: headingAttributes.level,
182
+ link: canBeLinked ? `${headingPageLink}#${headingAttributes.anchor}` : null
183
+ });
184
+ }
185
+ }
132
186
  }
133
- }, [pageIndex, postContent, onlyIncludeCurrentPage]);
134
- const {
135
- replaceBlocks
136
- } = (0, _data.useDispatch)(_blockEditor.store);
187
+
188
+ if ((0, _lodash.isEqual)(headings, _latestHeadings)) {
189
+ return null;
190
+ }
191
+
192
+ return _latestHeadings;
193
+ }, [clientId, onlyIncludeCurrentPage, headings]);
194
+ (0, _element.useEffect)(() => {
195
+ if (latestHeadings !== null) {
196
+ // This is required to keep undo working and not create 2 undo steps
197
+ // for each heading change.
198
+ __unstableMarkNextChangeAsNotPersistent();
199
+
200
+ setAttributes({
201
+ headings: latestHeadings
202
+ });
203
+ }
204
+ }, [latestHeadings]);
205
+ const headingTree = (0, _utils.linearToNestedHeadingList)(headings);
137
206
  const toolbarControls = listBlockExists && (0, _element.createElement)(_blockEditor.BlockControls, null, (0, _element.createElement)(_components.ToolbarGroup, null, (0, _element.createElement)(_components.ToolbarButton, {
138
207
  onClick: () => replaceBlocks(clientId, (0, _blocks.createBlock)('core/list', {
208
+ ordered: true,
139
209
  values: (0, _element.renderToString)((0, _element.createElement)(_list.default, {
140
210
  nestedHeadingList: headingTree
141
211
  }))
142
212
  }))
143
213
  }, (0, _i18n.__)('Convert to static list'))));
144
214
  const inspectorControls = (0, _element.createElement)(_blockEditor.InspectorControls, null, (0, _element.createElement)(_components.PanelBody, {
145
- title: (0, _i18n.__)('Table of Contents settings')
215
+ title: (0, _i18n.__)('Settings')
146
216
  }, (0, _element.createElement)(_components.ToggleControl, {
147
217
  label: (0, _i18n.__)('Only include current page'),
148
218
  checked: onlyIncludeCurrentPage,
@@ -157,14 +227,16 @@ function TableOfContentsEdit(_ref) {
157
227
  if (headings.length === 0) {
158
228
  return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)("div", blockProps, (0, _element.createElement)(_components.Placeholder, {
159
229
  icon: (0, _element.createElement)(_blockEditor.BlockIcon, {
160
- icon: "list-view"
230
+ icon: _icon.default
161
231
  }),
162
232
  label: "Table of Contents",
163
233
  instructions: (0, _i18n.__)('Start adding Heading blocks to create a table of contents. Headings with HTML anchors will be linked here.')
164
234
  })), inspectorControls);
165
235
  }
166
236
 
167
- return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)("nav", blockProps, (0, _element.createElement)("ul", null, (0, _element.createElement)(_list.default, {
237
+ return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)("nav", blockProps, (0, _element.createElement)("ol", {
238
+ ref: disabledRef
239
+ }, (0, _element.createElement)(_list.default, {
168
240
  nestedHeadingList: headingTree
169
241
  }))), toolbarControls, inspectorControls);
170
242
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-library/src/table-of-contents/edit.js"],"names":["TableOfContentsEdit","attributes","onlyIncludeCurrentPage","clientId","setAttributes","blockProps","headings","setHeadings","headingTree","setHeadingTree","listBlockExists","postContent","select","blocksStore","getBlockType","getEditedPostContent","pageIndex","getBlockAttributes","getBlockIndex","getBlockName","getBlockOrder","blockEditorStore","blockIndex","blockOrder","page","i","blockName","pageBreaks","content","match","undefined","length","latestHeadings","pagesOfContent","split","replaceBlocks","toolbarControls","values","inspectorControls","value"],"mappings":";;;;;;;;;AAwBA;;AArBA;;AAKA;;AAOA;;AACA;;AAOA;;AAEA;;AAKA;;AACA;;AA/BA;AACA;AACA;;AAGA;AACA;AACA;;AAoBA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,mBAAT,OAIX;AAAA,MAJyC;AAC5CC,IAAAA,UAAU,EAAE;AAAEC,MAAAA;AAAF,KADgC;AAE5CC,IAAAA,QAF4C;AAG5CC,IAAAA;AAH4C,GAIzC;AACH,QAAMC,UAAU,GAAG,iCAAnB,CADG,CAGH;;AACA,QAAM,CAAEC,QAAF,EAAYC,WAAZ,IAA4B,uBAAU,EAAV,CAAlC;AACA,QAAM,CAAEC,WAAF,EAAeC,cAAf,IAAkC,uBAAU,EAAV,CAAxC;AAEA,QAAM;AAAEC,IAAAA,eAAF;AAAmBC,IAAAA;AAAnB,MAAmC,qBACtCC,MAAF,KAAgB;AACfF,IAAAA,eAAe,EAAE,CAA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AJf;AAMC,IAAA,IAAI,EACHrC,sBAAsB,GACnB,cACA,2EADA,CADmB,GAInB,cACA,mFADA;AAXL,IADD,CADD,CADD,CAhHG,CAuIH;AACA;AACA;;AACA,MAAKI,QAAQ,CAACyB,MAAT,KAAoB,CAAzB,EAA6B;AAC5B,WACC,qDACC,mCAAU1B,UAAV,EACC,4BAAC,uBAAD;AACC,MAAA,IAAI,EAAG,4BAAC,sBAAD;AAAW,QAAA,IAAI,EAAC;AAAhB,QADR;AAEC,MAAA,KAAK,EAAC,mBAFP;AAGC,MAAA,YAAY,EAAG,cACd,4GADc;AAHhB,MADD,CADD,EAUGiC,iBAVH,CADD;AAcA;;AAED,SACC,qDACC,mCAAUjC,UAAV,EACC,wCACC,4BAAC,aAAD;AAAqB,IAAA,iBAAiB,EAAGG;AAAzC,IADD,CADD,CADD,EAMG4B,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":["TableOfContentsEdit","attributes","headings","onlyIncludeCurrentPage","clientId","setAttributes","blockProps","disabledRef","listBlockExists","select","blocksStore","getBlockType","__unstableMarkNextChangeAsNotPersistent","replaceBlocks","blockEditorStore","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","icon"],"mappings":";;;;;;;;;AA0BA;;AAvBA;;AAKA;;AAOA;;AACA;;AAOA;;AACA;;AACA;;AAEA;;AACA;;AAKA;;AACA;;AACA;;AAnCA;AACA;AACA;;AAGA;AACA;AACA;;AAuBA;AACA;AACA;;AAKA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,mBAAT,OAIX;AAAA,MAJyC;AAC5CC,IAAAA,UAAU,EAAE;AAAEC,MAAAA,QAAQ,GAAG,EAAb;AAAiBC,MAAAA;AAAjB,KADgC;AAE5CC,IAAAA,QAF4C;AAG5CC,IAAAA;AAH4C,GAIzC;AACH,QAAMC,UAAU,GAAG,iCAAnB;AACA,QAAMC,WAAW,GAAG,2BAApB;AAEA,QAAMC,eAAe,GAAG,qBACrBC,MAAF,IAAc,CAAC,CAAEA,MAAM,CAAEC,aAAF,CAAN,CAAsBC,YAAtB,CAAoC,WAApC,CADM,EAEvB,EAFuB,CAAxB;AAKA,QAAM;AACLC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L,IADD,CADD,CADD,CA3LG,CAkNH;AACA;AACA;;AACA,MAAKD,QAAQ,CAACsB,MAAT,KAAoB,CAAzB,EAA6B;AAC5B,WACC,qDACC,mCAAUlB,UAAV,EACC,4BAAC,uBAAD;AACC,MAAA,IAAI,EAAG,4BAAC,sBAAD;AAAW,QAAA,IAAI,EAAG8C;AAAlB,QADR;AAEC,MAAA,KAAK,EAAC,mBAFP;AAGC,MAAA,YAAY,EAAG,cACd,4GADc;AAHhB,MADD,CADD,EAUGF,iBAVH,CADD;AAcA;;AAED,SACC,qDACC,mCAAU5C,UAAV,EACC;AAAI,IAAA,GAAG,EAAGC;AAAV,KACC,4BAAC,aAAD;AAAqB,IAAA,iBAAiB,EAAGuC;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"]}
@@ -11,12 +11,15 @@ var _edit = _interopRequireDefault(require("./edit"));
11
11
 
12
12
  var _icon = _interopRequireDefault(require("./icon"));
13
13
 
14
+ var _save = _interopRequireDefault(require("./save"));
15
+
14
16
  /**
15
17
  * Internal dependencies
16
18
  */
17
19
  const metadata = {
18
20
  $schema: "https://schemas.wp.org/trunk/block.json",
19
21
  apiVersion: 2,
22
+ __experimental: true,
20
23
  name: "core/table-of-contents",
21
24
  title: "Table of Contents",
22
25
  category: "layout",
@@ -24,15 +27,21 @@ const metadata = {
24
27
  keywords: ["document outline", "summary"],
25
28
  textdomain: "default",
26
29
  attributes: {
30
+ headings: {
31
+ type: "array",
32
+ items: {
33
+ type: "object"
34
+ }
35
+ },
27
36
  onlyIncludeCurrentPage: {
28
37
  type: "boolean",
29
38
  "default": false
30
39
  }
31
40
  },
32
- usesContext: ["postId"],
33
41
  supports: {
34
42
  html: false
35
- }
43
+ },
44
+ example: {}
36
45
  };
37
46
  exports.metadata = metadata;
38
47
  const {
@@ -41,7 +50,8 @@ const {
41
50
  exports.name = name;
42
51
  const settings = {
43
52
  icon: _icon.default,
44
- edit: _edit.default
53
+ edit: _edit.default,
54
+ save: _save.default
45
55
  };
46
56
  exports.settings = settings;
47
57
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-library/src/table-of-contents/index.js"],"names":["name","metadata","settings","icon","edit"],"mappings":";;;;;;;;;AAIA;;AACA;;AALA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;AAKA,MAAM;AAAEA,EAAAA;AAAF,IAAWC,QAAjB;;AAIO,MAAMC,QAAQ,GAAG;AACvBC,EAAAA,IAAI,EAAJA,aADuB;AAEvBC,EAAAA,IAAI,EAAJA;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":["name","metadata","settings","icon","edit","save"],"mappings":";;;;;;;;;AAIA;;AACA;;AACA;;AANA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAM;AAAEA,EAAAA;AAAF,IAAWC,QAAjB;;AAIO,MAAMC,QAAQ,GAAG;AACvBC,EAAAA,IAAI,EAAJA,aADuB;AAEvBC,EAAAA,IAAI,EAAJA,aAFuB;AAGvBC,EAAAA,IAAI,EAAJA;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"]}
@@ -7,28 +7,35 @@ exports.default = TableOfContentsList;
7
7
 
8
8
  var _element = require("@wordpress/element");
9
9
 
10
+ /**
11
+ * WordPress dependencies
12
+ */
13
+
14
+ /**
15
+ * Internal dependencies
16
+ */
10
17
  const ENTRY_CLASS_NAME = 'wp-block-table-of-contents__entry';
11
18
 
12
19
  function TableOfContentsList(_ref) {
13
20
  let {
14
21
  nestedHeadingList
15
22
  } = _ref;
16
- return nestedHeadingList.map((childNode, index) => {
23
+ return (0, _element.createElement)(_element.Fragment, null, nestedHeadingList.map((node, index) => {
17
24
  const {
18
- anchor,
19
- content
20
- } = childNode.heading;
21
- const entry = anchor ? (0, _element.createElement)("a", {
25
+ content,
26
+ link
27
+ } = node.heading;
28
+ const entry = link ? (0, _element.createElement)("a", {
22
29
  className: ENTRY_CLASS_NAME,
23
- href: anchor
30
+ href: link
24
31
  }, content) : (0, _element.createElement)("span", {
25
32
  className: ENTRY_CLASS_NAME
26
33
  }, content);
27
34
  return (0, _element.createElement)("li", {
28
35
  key: index
29
- }, entry, childNode.children ? (0, _element.createElement)("ul", null, (0, _element.createElement)(TableOfContentsList, {
30
- nestedHeadingList: childNode.children
36
+ }, entry, node.children ? (0, _element.createElement)("ol", null, (0, _element.createElement)(TableOfContentsList, {
37
+ nestedHeadingList: node.children
31
38
  })) : null);
32
- });
39
+ }));
33
40
  }
34
41
  //# 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;;AAEe,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,wCACC,4BAAC,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;;AAEe,SAASC,mBAAT,OAIA;AAAA,MAJ8B;AAC5CC,IAAAA;AAD4C,GAI9B;AACd,SACC,qDACGA,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,wCACC,4BAAC,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,40 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = save;
9
+
10
+ var _element = require("@wordpress/element");
11
+
12
+ var _blockEditor = require("@wordpress/block-editor");
13
+
14
+ var _list = _interopRequireDefault(require("./list"));
15
+
16
+ var _utils = require("./utils");
17
+
18
+ /**
19
+ * WordPress dependencies
20
+ */
21
+
22
+ /**
23
+ * Internal dependencies
24
+ */
25
+ function save(_ref) {
26
+ let {
27
+ attributes: {
28
+ headings = []
29
+ }
30
+ } = _ref;
31
+
32
+ if (headings.length === 0) {
33
+ return null;
34
+ }
35
+
36
+ return (0, _element.createElement)("nav", _blockEditor.useBlockProps.save(), (0, _element.createElement)("ol", null, (0, _element.createElement)(_list.default, {
37
+ nestedHeadingList: (0, _utils.linearToNestedHeadingList)(headings)
38
+ })));
39
+ }
40
+ //# sourceMappingURL=save.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/block-library/src/table-of-contents/save.js"],"names":["save","attributes","headings","length","useBlockProps"],"mappings":";;;;;;;;;;;AAGA;;AAKA;;AACA;;AATA;AACA;AACA;;AAGA;AACA;AACA;AAIe,SAASA,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,mCAAUC,2BAAcJ,IAAd,EAAV,EACC,wCACC,4BAAC,aAAD;AACC,IAAA,iBAAiB,EAAG,sCAA2BE,QAA3B;AADrB,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"]}
@@ -3,84 +3,17 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getHeadingsFromContent = getHeadingsFromContent;
7
- exports.getHeadingsFromHeadingElements = getHeadingsFromHeadingElements;
8
6
  exports.linearToNestedHeadingList = linearToNestedHeadingList;
9
7
 
10
- /**
11
- * @typedef WPHeadingData
12
- *
13
- * @property {string} anchor The anchor link to the heading, or '' if none.
14
- * @property {string} content The plain text content of the heading.
15
- * @property {number} level The heading level.
16
- */
17
-
18
- /**
19
- * Extracts text, anchor, and level from a list of heading elements.
20
- *
21
- * @param {NodeList} headingElements The list of heading elements.
22
- *
23
- * @return {WPHeadingData[]} The list of heading parameters.
24
- */
25
- function getHeadingsFromHeadingElements(headingElements) {
26
- return [...headingElements].map(heading => ({
27
- // A little hacky, but since we know at this point that the tag will
28
- // be an H1-H6, we can just grab the 2nd character of the tag name and
29
- // convert it to an integer. Should be faster than conditionals.
30
- level: parseInt(heading.tagName[1], 10),
31
- anchor: heading.hasAttribute('id') ? `#${heading.id}` : '',
32
- content: heading.textContent
33
- }));
34
- }
35
- /**
36
- * Extracts heading data from the provided content.
37
- *
38
- * @param {string} content The content to extract heading data from.
39
- *
40
- * @return {WPHeadingData[]} The list of heading parameters.
41
- */
42
-
43
-
44
- function getHeadingsFromContent(content) {
45
- // Create a temporary container to put the post content into, so we can
46
- // use the DOM to find all the headings.
47
- const tempPostContentDOM = document.createElement('div');
48
- tempPostContentDOM.innerHTML = content; // Remove template elements so that headings inside them aren't counted.
49
- // This is only needed for IE11, which doesn't recognize the element and
50
- // treats it like a div.
51
-
52
- for (const template of tempPostContentDOM.querySelectorAll('template')) {
53
- template.remove();
54
- }
55
-
56
- const headingElements = tempPostContentDOM.querySelectorAll('h1:not(:empty), h2:not(:empty), h3:not(:empty), h4:not(:empty), h5:not(:empty), h6:not(:empty)');
57
- return getHeadingsFromHeadingElements(headingElements);
58
- }
59
- /**
60
- * @typedef WPNestedHeadingData
61
- *
62
- * @property {WPHeadingData} heading The heading content, anchor,
63
- * and level.
64
- * @property {number} index The index of this heading
65
- * node in the entire nested
66
- * list of heading data.
67
- * @property {WPNestedHeadingData[]|null} children The sub-headings of this
68
- * heading, if any.
69
- */
70
-
71
8
  /**
72
9
  * Takes a flat list of heading parameters and nests them based on each header's
73
10
  * immediate parent's level.
74
11
  *
75
- * @param {WPHeadingData[]} headingList The flat list of headings to nest.
76
- * @param {number} index The current list index.
12
+ * @param headingList The flat list of headings to nest.
77
13
  *
78
- * @return {WPNestedHeadingData[]} The nested list of headings.
14
+ * @return The nested list of headings.
79
15
  */
80
-
81
-
82
16
  function linearToNestedHeadingList(headingList) {
83
- let index = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
84
17
  const nestedHeadingList = [];
85
18
  headingList.forEach((heading, key) => {
86
19
  if (heading.content === '') {
@@ -89,13 +22,15 @@ function linearToNestedHeadingList(headingList) {
89
22
 
90
23
 
91
24
  if (heading.level === headingList[0].level) {
25
+ var _headingList;
26
+
92
27
  // Check that the next iteration will return a value.
93
28
  // If it does and the next level is greater than the current level,
94
29
  // the next iteration becomes a child of the current iteration.
95
- if (headingList[key + 1] !== undefined && headingList[key + 1].level > heading.level) {
96
- // We need to calculate the last index before the next iteration that has the same level (siblings).
97
- // We then use this last index to slice the array for use in recursion.
98
- // This prevents duplicate nodes.
30
+ if (((_headingList = headingList[key + 1]) === null || _headingList === void 0 ? void 0 : _headingList.level) > heading.level) {
31
+ // We must calculate the last index before the next iteration that
32
+ // has the same level (siblings). We then use this index to slice
33
+ // the array for use in recursion. This prevents duplicate nodes.
99
34
  let endOfSlice = headingList.length;
100
35
 
101
36
  for (let i = key + 1; i < headingList.length; i++) {
@@ -103,19 +38,18 @@ function linearToNestedHeadingList(headingList) {
103
38
  endOfSlice = i;
104
39
  break;
105
40
  }
106
- } // We found a child node: Push a new node onto the return array with children.
41
+ } // We found a child node: Push a new node onto the return array
42
+ // with children.
107
43
 
108
44
 
109
45
  nestedHeadingList.push({
110
46
  heading,
111
- index: index + key,
112
- children: linearToNestedHeadingList(headingList.slice(key + 1, endOfSlice), index + key + 1)
47
+ children: linearToNestedHeadingList(headingList.slice(key + 1, endOfSlice))
113
48
  });
114
49
  } else {
115
50
  // No child node: Push a new node onto the return array.
116
51
  nestedHeadingList.push({
117
52
  heading,
118
- index: index + key,
119
53
  children: null
120
54
  });
121
55
  }