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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (381) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +1 -1
  3. package/build/block/edit.js +53 -2
  4. package/build/block/edit.js.map +1 -1
  5. package/build/button/edit.js +7 -4
  6. package/build/button/edit.js.map +1 -1
  7. package/build/button/index.js +11 -2
  8. package/build/button/index.js.map +1 -1
  9. package/build/button/save.js +10 -4
  10. package/build/button/save.js.map +1 -1
  11. package/build/buttons/edit.js +12 -3
  12. package/build/buttons/edit.js.map +1 -1
  13. package/build/code/edit.js +8 -2
  14. package/build/code/edit.js.map +1 -1
  15. package/build/code/index.js +7 -1
  16. package/build/code/index.js.map +1 -1
  17. package/build/column/index.js +1 -0
  18. package/build/column/index.js.map +1 -1
  19. package/build/columns/index.js +2 -0
  20. package/build/columns/index.js.map +1 -1
  21. package/build/file/edit.native.js +1 -1
  22. package/build/file/edit.native.js.map +1 -1
  23. package/build/file/index.js +2 -1
  24. package/build/file/index.js.map +1 -1
  25. package/build/file/utils/index.js +1 -15
  26. package/build/file/utils/index.js.map +1 -1
  27. package/build/file/view.js +14 -1
  28. package/build/file/view.js.map +1 -1
  29. package/build/footnotes/edit.js +12 -2
  30. package/build/footnotes/edit.js.map +1 -1
  31. package/build/gallery/edit.js +1 -1
  32. package/build/gallery/edit.js.map +1 -1
  33. package/build/group/edit.js +0 -1
  34. package/build/group/edit.js.map +1 -1
  35. package/build/group/index.js +4 -0
  36. package/build/group/index.js.map +1 -1
  37. package/build/heading/edit.js +0 -1
  38. package/build/heading/edit.js.map +1 -1
  39. package/build/heading/index.js +2 -0
  40. package/build/heading/index.js.map +1 -1
  41. package/build/heading/transforms.js +3 -6
  42. package/build/heading/transforms.js.map +1 -1
  43. package/build/image/deprecated.js +191 -7
  44. package/build/image/deprecated.js.map +1 -1
  45. package/build/image/edit.js +27 -12
  46. package/build/image/edit.js.map +1 -1
  47. package/build/image/image.js +75 -40
  48. package/build/image/image.js.map +1 -1
  49. package/build/image/index.js +7 -4
  50. package/build/image/index.js.map +1 -1
  51. package/build/image/{view-interactivity.js → view.js} +1 -1
  52. package/build/image/view.js.map +1 -0
  53. package/build/list/deprecated.js +93 -1
  54. package/build/list/deprecated.js.map +1 -1
  55. package/build/list/edit.js +10 -10
  56. package/build/list/edit.js.map +1 -1
  57. package/build/list/ordered-list-settings.js +10 -10
  58. package/build/list/ordered-list-settings.js.map +1 -1
  59. package/build/list/save.js +4 -2
  60. package/build/list/save.js.map +1 -1
  61. package/build/list/utils.js +21 -2
  62. package/build/list/utils.js.map +1 -1
  63. package/build/navigation/constants.js +1 -1
  64. package/build/navigation/constants.js.map +1 -1
  65. package/build/navigation/index.js +4 -2
  66. package/build/navigation/index.js.map +1 -1
  67. package/build/navigation/view.js +168 -82
  68. package/build/navigation/view.js.map +1 -1
  69. package/build/navigation-link/edit.js +3 -9
  70. package/build/navigation-link/edit.js.map +1 -1
  71. package/build/navigation-link/transforms.js +24 -0
  72. package/build/navigation-link/transforms.js.map +1 -1
  73. package/build/page-list/edit.js +2 -1
  74. package/build/page-list/edit.js.map +1 -1
  75. package/build/post-comments-form/edit.js +10 -2
  76. package/build/post-comments-form/edit.js.map +1 -1
  77. package/build/post-comments-form/form.js +5 -3
  78. package/build/post-comments-form/form.js.map +1 -1
  79. package/build/post-content/edit.js +8 -7
  80. package/build/post-content/edit.js.map +1 -1
  81. package/build/post-content/index.js +3 -0
  82. package/build/post-content/index.js.map +1 -1
  83. package/build/post-featured-image/overlay.js +2 -1
  84. package/build/post-featured-image/overlay.js.map +1 -1
  85. package/build/preformatted/edit.js +4 -1
  86. package/build/preformatted/edit.js.map +1 -1
  87. package/build/preformatted/index.js +1 -1
  88. package/build/preformatted/index.js.map +1 -1
  89. package/build/pullquote/deprecated.js +6 -7
  90. package/build/pullquote/deprecated.js.map +1 -1
  91. package/build/query/edit/enhanced-pagination-modal.js +56 -0
  92. package/build/query/edit/enhanced-pagination-modal.js.map +1 -0
  93. package/build/query/edit/inspector-controls/enhanced-pagination-control.js +42 -0
  94. package/build/query/edit/inspector-controls/enhanced-pagination-control.js.map +1 -0
  95. package/build/query/edit/inspector-controls/index.js +8 -25
  96. package/build/query/edit/inspector-controls/index.js.map +1 -1
  97. package/build/query/edit/query-content.js +8 -2
  98. package/build/query/edit/query-content.js.map +1 -1
  99. package/build/query/utils.js +19 -0
  100. package/build/query/utils.js.map +1 -1
  101. package/build/query/view.js +4 -5
  102. package/build/query/view.js.map +1 -1
  103. package/build/search/index.js +1 -0
  104. package/build/search/index.js.map +1 -1
  105. package/build/search/view.js +81 -150
  106. package/build/search/view.js.map +1 -1
  107. package/build/social-link/edit.native.js +3 -1
  108. package/build/social-link/edit.native.js.map +1 -1
  109. package/build/table/edit.js +7 -7
  110. package/build/table/edit.js.map +1 -1
  111. package/build/table-of-contents/edit.js +2 -130
  112. package/build/table-of-contents/edit.js.map +1 -1
  113. package/build/table-of-contents/hooks.js +145 -0
  114. package/build/table-of-contents/hooks.js.map +1 -0
  115. package/build/table-of-contents/index.js +2 -1
  116. package/build/table-of-contents/index.js.map +1 -1
  117. package/build/verse/edit.js +4 -1
  118. package/build/verse/edit.js.map +1 -1
  119. package/build/verse/index.js +1 -1
  120. package/build/verse/index.js.map +1 -1
  121. package/build-module/block/edit.js +54 -3
  122. package/build-module/block/edit.js.map +1 -1
  123. package/build-module/button/edit.js +7 -4
  124. package/build-module/button/edit.js.map +1 -1
  125. package/build-module/button/index.js +11 -2
  126. package/build-module/button/index.js.map +1 -1
  127. package/build-module/button/save.js +10 -4
  128. package/build-module/button/save.js.map +1 -1
  129. package/build-module/buttons/edit.js +12 -3
  130. package/build-module/buttons/edit.js.map +1 -1
  131. package/build-module/code/edit.js +8 -2
  132. package/build-module/code/edit.js.map +1 -1
  133. package/build-module/code/index.js +7 -1
  134. package/build-module/code/index.js.map +1 -1
  135. package/build-module/column/index.js +1 -0
  136. package/build-module/column/index.js.map +1 -1
  137. package/build-module/columns/index.js +2 -0
  138. package/build-module/columns/index.js.map +1 -1
  139. package/build-module/file/edit.native.js +1 -1
  140. package/build-module/file/edit.native.js.map +1 -1
  141. package/build-module/file/index.js +2 -1
  142. package/build-module/file/index.js.map +1 -1
  143. package/build-module/file/utils/index.js +0 -13
  144. package/build-module/file/utils/index.js.map +1 -1
  145. package/build-module/file/view.js +14 -2
  146. package/build-module/file/view.js.map +1 -1
  147. package/build-module/footnotes/edit.js +12 -2
  148. package/build-module/footnotes/edit.js.map +1 -1
  149. package/build-module/gallery/edit.js +1 -1
  150. package/build-module/gallery/edit.js.map +1 -1
  151. package/build-module/group/edit.js +0 -1
  152. package/build-module/group/edit.js.map +1 -1
  153. package/build-module/group/index.js +4 -0
  154. package/build-module/group/index.js.map +1 -1
  155. package/build-module/heading/edit.js +0 -1
  156. package/build-module/heading/edit.js.map +1 -1
  157. package/build-module/heading/index.js +2 -0
  158. package/build-module/heading/index.js.map +1 -1
  159. package/build-module/heading/transforms.js +3 -6
  160. package/build-module/heading/transforms.js.map +1 -1
  161. package/build-module/image/deprecated.js +191 -7
  162. package/build-module/image/deprecated.js.map +1 -1
  163. package/build-module/image/edit.js +27 -12
  164. package/build-module/image/edit.js.map +1 -1
  165. package/build-module/image/image.js +77 -42
  166. package/build-module/image/image.js.map +1 -1
  167. package/build-module/image/index.js +7 -4
  168. package/build-module/image/index.js.map +1 -1
  169. package/build-module/image/{view-interactivity.js → view.js} +1 -1
  170. package/build-module/image/view.js.map +1 -0
  171. package/build-module/list/deprecated.js +95 -3
  172. package/build-module/list/deprecated.js.map +1 -1
  173. package/build-module/list/edit.js +10 -10
  174. package/build-module/list/edit.js.map +1 -1
  175. package/build-module/list/ordered-list-settings.js +10 -10
  176. package/build-module/list/ordered-list-settings.js.map +1 -1
  177. package/build-module/list/save.js +4 -2
  178. package/build-module/list/save.js.map +1 -1
  179. package/build-module/list/utils.js +20 -2
  180. package/build-module/list/utils.js.map +1 -1
  181. package/build-module/navigation/constants.js +1 -1
  182. package/build-module/navigation/constants.js.map +1 -1
  183. package/build-module/navigation/index.js +4 -2
  184. package/build-module/navigation/index.js.map +1 -1
  185. package/build-module/navigation/view.js +168 -83
  186. package/build-module/navigation/view.js.map +1 -1
  187. package/build-module/navigation-link/edit.js +3 -9
  188. package/build-module/navigation-link/edit.js.map +1 -1
  189. package/build-module/navigation-link/transforms.js +24 -0
  190. package/build-module/navigation-link/transforms.js.map +1 -1
  191. package/build-module/page-list/edit.js +2 -1
  192. package/build-module/page-list/edit.js.map +1 -1
  193. package/build-module/post-comments-form/edit.js +10 -2
  194. package/build-module/post-comments-form/edit.js.map +1 -1
  195. package/build-module/post-comments-form/form.js +5 -3
  196. package/build-module/post-comments-form/form.js.map +1 -1
  197. package/build-module/post-content/edit.js +8 -7
  198. package/build-module/post-content/edit.js.map +1 -1
  199. package/build-module/post-content/index.js +3 -0
  200. package/build-module/post-content/index.js.map +1 -1
  201. package/build-module/post-featured-image/overlay.js +2 -1
  202. package/build-module/post-featured-image/overlay.js.map +1 -1
  203. package/build-module/preformatted/edit.js +4 -1
  204. package/build-module/preformatted/edit.js.map +1 -1
  205. package/build-module/preformatted/index.js +1 -1
  206. package/build-module/preformatted/index.js.map +1 -1
  207. package/build-module/pullquote/deprecated.js +6 -7
  208. package/build-module/pullquote/deprecated.js.map +1 -1
  209. package/build-module/query/edit/enhanced-pagination-modal.js +50 -0
  210. package/build-module/query/edit/enhanced-pagination-modal.js.map +1 -0
  211. package/build-module/query/edit/inspector-controls/enhanced-pagination-control.js +35 -0
  212. package/build-module/query/edit/inspector-controls/enhanced-pagination-control.js.map +1 -0
  213. package/build-module/query/edit/inspector-controls/index.js +9 -26
  214. package/build-module/query/edit/inspector-controls/index.js.map +1 -1
  215. package/build-module/query/edit/query-content.js +8 -2
  216. package/build-module/query/edit/query-content.js.map +1 -1
  217. package/build-module/query/utils.js +17 -0
  218. package/build-module/query/utils.js.map +1 -1
  219. package/build-module/query/view.js +4 -5
  220. package/build-module/query/view.js.map +1 -1
  221. package/build-module/search/index.js +1 -0
  222. package/build-module/search/index.js.map +1 -1
  223. package/build-module/search/view.js +81 -151
  224. package/build-module/search/view.js.map +1 -1
  225. package/build-module/social-link/edit.native.js +3 -1
  226. package/build-module/social-link/edit.native.js.map +1 -1
  227. package/build-module/table/edit.js +7 -7
  228. package/build-module/table/edit.js.map +1 -1
  229. package/build-module/table-of-contents/edit.js +3 -131
  230. package/build-module/table-of-contents/edit.js.map +1 -1
  231. package/build-module/table-of-contents/hooks.js +137 -0
  232. package/build-module/table-of-contents/hooks.js.map +1 -0
  233. package/build-module/table-of-contents/index.js +2 -1
  234. package/build-module/table-of-contents/index.js.map +1 -1
  235. package/build-module/verse/edit.js +4 -1
  236. package/build-module/verse/edit.js.map +1 -1
  237. package/build-module/verse/index.js +1 -1
  238. package/build-module/verse/index.js.map +1 -1
  239. package/build-style/cover/style-rtl.css +9 -0
  240. package/build-style/cover/style.css +9 -0
  241. package/build-style/editor-rtl.css +15 -9
  242. package/build-style/editor.css +15 -9
  243. package/build-style/file/style-rtl.css +5 -0
  244. package/build-style/file/style.css +5 -0
  245. package/build-style/heading/style-rtl.css +13 -0
  246. package/build-style/heading/style.css +13 -0
  247. package/build-style/navigation-link/editor-rtl.css +0 -9
  248. package/build-style/navigation-link/editor.css +0 -9
  249. package/build-style/paragraph/editor-rtl.css +5 -0
  250. package/build-style/paragraph/editor.css +5 -0
  251. package/build-style/paragraph/style-rtl.css +5 -0
  252. package/build-style/paragraph/style.css +5 -0
  253. package/build-style/post-navigation-link/style-rtl.css +3 -0
  254. package/build-style/post-navigation-link/style.css +3 -0
  255. package/build-style/query/editor-rtl.css +10 -0
  256. package/build-style/query/editor.css +10 -0
  257. package/build-style/query/style-rtl.css +1 -1
  258. package/build-style/query/style.css +1 -1
  259. package/build-style/reset-rtl.css +27 -27
  260. package/build-style/reset.css +27 -27
  261. package/build-style/style-rtl.css +35 -0
  262. package/build-style/style.css +35 -0
  263. package/package.json +32 -33
  264. package/src/audio/test/__snapshots__/edit.native.js.snap +78 -106
  265. package/src/avatar/index.php +2 -2
  266. package/src/block/edit.js +58 -2
  267. package/src/block/test/edit.native.js +2 -3
  268. package/src/button/block.json +11 -2
  269. package/src/button/edit.js +27 -11
  270. package/src/button/save.js +10 -4
  271. package/src/buttons/edit.js +13 -3
  272. package/src/buttons/test/edit.native.js +28 -24
  273. package/src/calendar/index.php +2 -2
  274. package/src/code/block.json +2 -1
  275. package/src/code/edit.js +13 -1
  276. package/src/code/index.js +5 -0
  277. package/src/column/block.json +1 -0
  278. package/src/columns/block.json +2 -0
  279. package/src/comment-template/index.php +1 -1
  280. package/src/comments-pagination-next/index.php +1 -1
  281. package/src/comments-pagination-previous/index.php +1 -1
  282. package/src/cover/style.scss +12 -1
  283. package/src/cover/test/edit.js +7 -7
  284. package/src/cover/test/edit.native.js +18 -27
  285. package/src/embed/test/index.native.js +30 -45
  286. package/src/file/block.json +2 -1
  287. package/src/file/edit.native.js +1 -1
  288. package/src/file/index.php +19 -21
  289. package/src/file/style.scss +6 -1
  290. package/src/file/test/__snapshots__/edit.native.js.snap +162 -218
  291. package/src/file/utils/index.js +0 -15
  292. package/src/file/view.js +14 -5
  293. package/src/footnotes/edit.js +13 -1
  294. package/src/gallery/edit.js +1 -1
  295. package/src/gallery/index.php +1 -1
  296. package/src/group/block.json +4 -0
  297. package/src/group/edit.js +0 -1
  298. package/src/heading/block.json +2 -0
  299. package/src/heading/edit.js +0 -1
  300. package/src/heading/style.scss +4 -0
  301. package/src/heading/transforms.js +1 -6
  302. package/src/image/block.json +7 -4
  303. package/src/image/deprecated.js +210 -7
  304. package/src/image/edit.js +43 -29
  305. package/src/image/image.js +86 -43
  306. package/src/image/index.php +251 -28
  307. package/src/latest-posts/index.php +1 -1
  308. package/src/list/deprecated.js +84 -3
  309. package/src/list/edit.js +6 -3
  310. package/src/list/ordered-list-settings.js +20 -5
  311. package/src/list/save.js +10 -1
  312. package/src/list/test/edit.native.js +2 -4
  313. package/src/list/utils.js +22 -1
  314. package/src/navigation/block.json +4 -2
  315. package/src/navigation/constants.js +1 -0
  316. package/src/navigation/index.php +85 -123
  317. package/src/navigation/view.js +192 -96
  318. package/src/navigation-link/edit.js +21 -36
  319. package/src/navigation-link/editor.scss +0 -8
  320. package/src/navigation-link/transforms.js +22 -0
  321. package/src/page-list/edit.js +2 -1
  322. package/src/paragraph/editor.scss +5 -0
  323. package/src/paragraph/style.scss +5 -0
  324. package/src/pattern/index.php +2 -2
  325. package/src/post-comments-form/edit.js +10 -0
  326. package/src/post-comments-form/form.js +7 -1
  327. package/src/post-content/block.json +3 -0
  328. package/src/post-content/edit.js +14 -6
  329. package/src/post-excerpt/index.php +2 -2
  330. package/src/post-featured-image/index.php +2 -2
  331. package/src/post-featured-image/overlay.js +1 -0
  332. package/src/post-navigation-link/index.php +0 -5
  333. package/src/post-navigation-link/style.scss +4 -0
  334. package/src/post-template/index.php +1 -1
  335. package/src/post-terms/index.php +5 -2
  336. package/src/preformatted/edit.js +5 -0
  337. package/src/preformatted/index.js +1 -1
  338. package/src/pullquote/deprecated.js +8 -13
  339. package/src/query/edit/enhanced-pagination-modal.js +65 -0
  340. package/src/query/edit/inspector-controls/enhanced-pagination-control.js +49 -0
  341. package/src/query/edit/inspector-controls/index.js +9 -45
  342. package/src/query/edit/query-content.js +8 -0
  343. package/src/query/editor.scss +10 -0
  344. package/src/query/index.php +29 -16
  345. package/src/query/style.scss +2 -2
  346. package/src/query/utils.js +22 -0
  347. package/src/query/view.js +5 -5
  348. package/src/query-pagination-next/index.php +1 -1
  349. package/src/query-pagination-previous/index.php +1 -1
  350. package/src/reset.scss +1 -1
  351. package/src/search/block.json +1 -0
  352. package/src/search/index.php +45 -4
  353. package/src/search/test/__snapshots__/edit.native.js.snap +265 -363
  354. package/src/search/view.js +70 -169
  355. package/src/social-link/edit.native.js +1 -1
  356. package/src/social-link/editor.native.scss +4 -0
  357. package/src/table/edit.js +21 -19
  358. package/src/table-of-contents/block.json +2 -1
  359. package/src/table-of-contents/edit.js +5 -162
  360. package/src/table-of-contents/hooks.js +156 -0
  361. package/src/verse/edit.js +5 -0
  362. package/src/verse/index.js +1 -1
  363. package/src/verse/test/edit.native.js +2 -3
  364. package/build/file/view-interactivity.js +0 -22
  365. package/build/file/view-interactivity.js.map +0 -1
  366. package/build/image/view-interactivity.js.map +0 -1
  367. package/build/navigation/view-interactivity.js +0 -172
  368. package/build/navigation/view-interactivity.js.map +0 -1
  369. package/build/navigation/view-modal.js +0 -115
  370. package/build/navigation/view-modal.js.map +0 -1
  371. package/build-module/file/view-interactivity.js +0 -18
  372. package/build-module/file/view-interactivity.js.map +0 -1
  373. package/build-module/image/view-interactivity.js.map +0 -1
  374. package/build-module/navigation/view-interactivity.js +0 -169
  375. package/build-module/navigation/view-interactivity.js.map +0 -1
  376. package/build-module/navigation/view-modal.js +0 -112
  377. package/build-module/navigation/view-modal.js.map +0 -1
  378. package/src/file/view-interactivity.js +0 -18
  379. package/src/navigation/view-interactivity.js +0 -196
  380. package/src/navigation/view-modal.js +0 -127
  381. /package/src/image/{view-interactivity.js → view.js} +0 -0
@@ -1 +1 @@
1
- {"version":3,"names":["_element","require","_classnames","_interopRequireDefault","_blockEditor","_i18n","_components","_icons","_blocks","_state","ALIGNMENT_CONTROLS","icon","alignLeft","title","__","align","alignCenter","alignRight","cellAriaLabel","head","body","foot","placeholder","TSection","name","props","TagName","createElement","TableEdit","attributes","setAttributes","insertBlocksAfter","isSelected","hasFixedLayout","caption","initialRowCount","setInitialRowCount","useState","initialColumnCount","setInitialColumnCount","selectedCell","setSelectedCell","colorProps","useColorProps","borderProps","useBorderProps","tableRef","useRef","hasTableCreated","setHasTableCreated","onChangeInitialColumnCount","count","onChangeInitialRowCount","onCreateTable","event","preventDefault","createTable","rowCount","parseInt","columnCount","onChangeFixedLayout","onChange","content","updateSelectedCell","cellAttributes","onChangeColumnAlignment","columnSelection","type","columnIndex","newAttributes","getCellAlignment","getCellAttribute","onToggleHeaderSection","toggleSection","onToggleFooterSection","onInsertRow","delta","sectionName","rowIndex","newRowIndex","insertRow","onInsertRowBefore","onInsertRowAfter","onDeleteRow","deleteRow","onInsertColumn","newColumnIndex","insertColumn","onInsertColumnBefore","onInsertColumnAfter","onDeleteColumn","deleteColumn","useEffect","current","querySelector","focus","sections","filter","isEmptyTableSection","tableControls","tableRowBefore","isDisabled","onClick","tableRowAfter","tableRowDelete","tableColumnBefore","tableColumnAfter","tableColumnDelete","renderedSections","map","key","cells","tag","CellTag","scope","colspan","rowspan","RichText","tagName","className","classnames","undefined","colSpan","rowSpan","value","onFocus","isEmpty","length","useBlockProps","ref","Fragment","BlockControls","group","AlignmentControl","label","alignmentControls","nextAlign","ToolbarDropdownMenu","hasArrowIndicator","table","controls","InspectorControls","PanelBody","ToggleControl","__nextHasNoMarginBottom","checked","hasSplitBorders","style","border","identifier","__experimentalGetElementClassName","__unstableOnSplitAtEnd","createBlock","getDefaultBlockName","Placeholder","BlockIcon","showColors","instructions","onSubmit","TextControl","min","Button","variant","_default","exports","default"],"sources":["@wordpress/block-library/src/table/edit.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useEffect, useRef, useState } from '@wordpress/element';\nimport {\n\tInspectorControls,\n\tBlockControls,\n\tRichText,\n\tBlockIcon,\n\tAlignmentControl,\n\tuseBlockProps,\n\t__experimentalUseColorProps as useColorProps,\n\t__experimentalUseBorderProps as useBorderProps,\n\t__experimentalGetElementClassName,\n} from '@wordpress/block-editor';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tButton,\n\tPanelBody,\n\tPlaceholder,\n\tTextControl,\n\tToggleControl,\n\tToolbarDropdownMenu,\n\t__experimentalHasSplitBorders as hasSplitBorders,\n} from '@wordpress/components';\nimport {\n\talignLeft,\n\talignRight,\n\talignCenter,\n\tblockTable as icon,\n\ttableColumnAfter,\n\ttableColumnBefore,\n\ttableColumnDelete,\n\ttableRowAfter,\n\ttableRowBefore,\n\ttableRowDelete,\n\ttable,\n} from '@wordpress/icons';\nimport { createBlock, getDefaultBlockName } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport {\n\tcreateTable,\n\tupdateSelectedCell,\n\tgetCellAttribute,\n\tinsertRow,\n\tdeleteRow,\n\tinsertColumn,\n\tdeleteColumn,\n\ttoggleSection,\n\tisEmptyTableSection,\n} from './state';\n\nconst ALIGNMENT_CONTROLS = [\n\t{\n\t\ticon: alignLeft,\n\t\ttitle: __( 'Align column left' ),\n\t\talign: 'left',\n\t},\n\t{\n\t\ticon: alignCenter,\n\t\ttitle: __( 'Align column center' ),\n\t\talign: 'center',\n\t},\n\t{\n\t\ticon: alignRight,\n\t\ttitle: __( 'Align column right' ),\n\t\talign: 'right',\n\t},\n];\n\nconst cellAriaLabel = {\n\thead: __( 'Header cell text' ),\n\tbody: __( 'Body cell text' ),\n\tfoot: __( 'Footer cell text' ),\n};\n\nconst placeholder = {\n\thead: __( 'Header label' ),\n\tfoot: __( 'Footer label' ),\n};\n\nfunction TSection( { name, ...props } ) {\n\tconst TagName = `t${ name }`;\n\treturn <TagName { ...props } />;\n}\n\nfunction TableEdit( {\n\tattributes,\n\tsetAttributes,\n\tinsertBlocksAfter,\n\tisSelected,\n} ) {\n\tconst { hasFixedLayout, caption, head, foot } = attributes;\n\tconst [ initialRowCount, setInitialRowCount ] = useState( 2 );\n\tconst [ initialColumnCount, setInitialColumnCount ] = useState( 2 );\n\tconst [ selectedCell, setSelectedCell ] = useState();\n\n\tconst colorProps = useColorProps( attributes );\n\tconst borderProps = useBorderProps( attributes );\n\n\tconst tableRef = useRef();\n\tconst [ hasTableCreated, setHasTableCreated ] = useState( false );\n\n\t/**\n\t * Updates the initial column count used for table creation.\n\t *\n\t * @param {number} count New initial column count.\n\t */\n\tfunction onChangeInitialColumnCount( count ) {\n\t\tsetInitialColumnCount( count );\n\t}\n\n\t/**\n\t * Updates the initial row count used for table creation.\n\t *\n\t * @param {number} count New initial row count.\n\t */\n\tfunction onChangeInitialRowCount( count ) {\n\t\tsetInitialRowCount( count );\n\t}\n\n\t/**\n\t * Creates a table based on dimensions in local state.\n\t *\n\t * @param {Object} event Form submit event.\n\t */\n\tfunction onCreateTable( event ) {\n\t\tevent.preventDefault();\n\n\t\tsetAttributes(\n\t\t\tcreateTable( {\n\t\t\t\trowCount: parseInt( initialRowCount, 10 ) || 2,\n\t\t\t\tcolumnCount: parseInt( initialColumnCount, 10 ) || 2,\n\t\t\t} )\n\t\t);\n\t\tsetHasTableCreated( true );\n\t}\n\n\t/**\n\t * Toggles whether the table has a fixed layout or not.\n\t */\n\tfunction onChangeFixedLayout() {\n\t\tsetAttributes( { hasFixedLayout: ! hasFixedLayout } );\n\t}\n\n\t/**\n\t * Changes the content of the currently selected cell.\n\t *\n\t * @param {Array} content A RichText content value.\n\t */\n\tfunction onChange( content ) {\n\t\tif ( ! selectedCell ) {\n\t\t\treturn;\n\t\t}\n\n\t\tsetAttributes(\n\t\t\tupdateSelectedCell(\n\t\t\t\tattributes,\n\t\t\t\tselectedCell,\n\t\t\t\t( cellAttributes ) => ( {\n\t\t\t\t\t...cellAttributes,\n\t\t\t\t\tcontent,\n\t\t\t\t} )\n\t\t\t)\n\t\t);\n\t}\n\n\t/**\n\t * Align text within the a column.\n\t *\n\t * @param {string} align The new alignment to apply to the column.\n\t */\n\tfunction onChangeColumnAlignment( align ) {\n\t\tif ( ! selectedCell ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Convert the cell selection to a column selection so that alignment\n\t\t// is applied to the entire column.\n\t\tconst columnSelection = {\n\t\t\ttype: 'column',\n\t\t\tcolumnIndex: selectedCell.columnIndex,\n\t\t};\n\n\t\tconst newAttributes = updateSelectedCell(\n\t\t\tattributes,\n\t\t\tcolumnSelection,\n\t\t\t( cellAttributes ) => ( {\n\t\t\t\t...cellAttributes,\n\t\t\t\talign,\n\t\t\t} )\n\t\t);\n\t\tsetAttributes( newAttributes );\n\t}\n\n\t/**\n\t * Get the alignment of the currently selected cell.\n\t *\n\t * @return {string | undefined} The new alignment to apply to the column.\n\t */\n\tfunction getCellAlignment() {\n\t\tif ( ! selectedCell ) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn getCellAttribute( attributes, selectedCell, 'align' );\n\t}\n\n\t/**\n\t * Add or remove a `head` table section.\n\t */\n\tfunction onToggleHeaderSection() {\n\t\tsetAttributes( toggleSection( attributes, 'head' ) );\n\t}\n\n\t/**\n\t * Add or remove a `foot` table section.\n\t */\n\tfunction onToggleFooterSection() {\n\t\tsetAttributes( toggleSection( attributes, 'foot' ) );\n\t}\n\n\t/**\n\t * Inserts a row at the currently selected row index, plus `delta`.\n\t *\n\t * @param {number} delta Offset for selected row index at which to insert.\n\t */\n\tfunction onInsertRow( delta ) {\n\t\tif ( ! selectedCell ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { sectionName, rowIndex } = selectedCell;\n\t\tconst newRowIndex = rowIndex + delta;\n\n\t\tsetAttributes(\n\t\t\tinsertRow( attributes, {\n\t\t\t\tsectionName,\n\t\t\t\trowIndex: newRowIndex,\n\t\t\t} )\n\t\t);\n\t\t// Select the first cell of the new row.\n\t\tsetSelectedCell( {\n\t\t\tsectionName,\n\t\t\trowIndex: newRowIndex,\n\t\t\tcolumnIndex: 0,\n\t\t\ttype: 'cell',\n\t\t} );\n\t}\n\n\t/**\n\t * Inserts a row before the currently selected row.\n\t */\n\tfunction onInsertRowBefore() {\n\t\tonInsertRow( 0 );\n\t}\n\n\t/**\n\t * Inserts a row after the currently selected row.\n\t */\n\tfunction onInsertRowAfter() {\n\t\tonInsertRow( 1 );\n\t}\n\n\t/**\n\t * Deletes the currently selected row.\n\t */\n\tfunction onDeleteRow() {\n\t\tif ( ! selectedCell ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { sectionName, rowIndex } = selectedCell;\n\n\t\tsetSelectedCell();\n\t\tsetAttributes( deleteRow( attributes, { sectionName, rowIndex } ) );\n\t}\n\n\t/**\n\t * Inserts a column at the currently selected column index, plus `delta`.\n\t *\n\t * @param {number} delta Offset for selected column index at which to insert.\n\t */\n\tfunction onInsertColumn( delta = 0 ) {\n\t\tif ( ! selectedCell ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { columnIndex } = selectedCell;\n\t\tconst newColumnIndex = columnIndex + delta;\n\n\t\tsetAttributes(\n\t\t\tinsertColumn( attributes, {\n\t\t\t\tcolumnIndex: newColumnIndex,\n\t\t\t} )\n\t\t);\n\t\t// Select the first cell of the new column.\n\t\tsetSelectedCell( {\n\t\t\trowIndex: 0,\n\t\t\tcolumnIndex: newColumnIndex,\n\t\t\ttype: 'cell',\n\t\t} );\n\t}\n\n\t/**\n\t * Inserts a column before the currently selected column.\n\t */\n\tfunction onInsertColumnBefore() {\n\t\tonInsertColumn( 0 );\n\t}\n\n\t/**\n\t * Inserts a column after the currently selected column.\n\t */\n\tfunction onInsertColumnAfter() {\n\t\tonInsertColumn( 1 );\n\t}\n\n\t/**\n\t * Deletes the currently selected column.\n\t */\n\tfunction onDeleteColumn() {\n\t\tif ( ! selectedCell ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { sectionName, columnIndex } = selectedCell;\n\n\t\tsetSelectedCell();\n\t\tsetAttributes(\n\t\t\tdeleteColumn( attributes, { sectionName, columnIndex } )\n\t\t);\n\t}\n\n\tuseEffect( () => {\n\t\tif ( ! isSelected ) {\n\t\t\tsetSelectedCell();\n\t\t}\n\t}, [ isSelected ] );\n\n\tuseEffect( () => {\n\t\tif ( hasTableCreated ) {\n\t\t\ttableRef?.current\n\t\t\t\t?.querySelector( 'td[contentEditable=\"true\"]' )\n\t\t\t\t?.focus();\n\t\t\tsetHasTableCreated( false );\n\t\t}\n\t}, [ hasTableCreated ] );\n\n\tconst sections = [ 'head', 'body', 'foot' ].filter(\n\t\t( name ) => ! isEmptyTableSection( attributes[ name ] )\n\t);\n\n\tconst tableControls = [\n\t\t{\n\t\t\ticon: tableRowBefore,\n\t\t\ttitle: __( 'Insert row before' ),\n\t\t\tisDisabled: ! selectedCell,\n\t\t\tonClick: onInsertRowBefore,\n\t\t},\n\t\t{\n\t\t\ticon: tableRowAfter,\n\t\t\ttitle: __( 'Insert row after' ),\n\t\t\tisDisabled: ! selectedCell,\n\t\t\tonClick: onInsertRowAfter,\n\t\t},\n\t\t{\n\t\t\ticon: tableRowDelete,\n\t\t\ttitle: __( 'Delete row' ),\n\t\t\tisDisabled: ! selectedCell,\n\t\t\tonClick: onDeleteRow,\n\t\t},\n\t\t{\n\t\t\ticon: tableColumnBefore,\n\t\t\ttitle: __( 'Insert column before' ),\n\t\t\tisDisabled: ! selectedCell,\n\t\t\tonClick: onInsertColumnBefore,\n\t\t},\n\t\t{\n\t\t\ticon: tableColumnAfter,\n\t\t\ttitle: __( 'Insert column after' ),\n\t\t\tisDisabled: ! selectedCell,\n\t\t\tonClick: onInsertColumnAfter,\n\t\t},\n\t\t{\n\t\t\ticon: tableColumnDelete,\n\t\t\ttitle: __( 'Delete column' ),\n\t\t\tisDisabled: ! selectedCell,\n\t\t\tonClick: onDeleteColumn,\n\t\t},\n\t];\n\n\tconst renderedSections = sections.map( ( name ) => (\n\t\t<TSection name={ name } key={ name }>\n\t\t\t{ attributes[ name ].map( ( { cells }, rowIndex ) => (\n\t\t\t\t<tr key={ rowIndex }>\n\t\t\t\t\t{ cells.map(\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcontent,\n\t\t\t\t\t\t\t\ttag: CellTag,\n\t\t\t\t\t\t\t\tscope,\n\t\t\t\t\t\t\t\talign,\n\t\t\t\t\t\t\t\tcolspan,\n\t\t\t\t\t\t\t\trowspan,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tcolumnIndex\n\t\t\t\t\t\t) => (\n\t\t\t\t\t\t\t<RichText\n\t\t\t\t\t\t\t\ttagName={ CellTag }\n\t\t\t\t\t\t\t\tkey={ columnIndex }\n\t\t\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t[ `has-text-align-${ align }` ]: align,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t'wp-block-table__cell-content'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tscope={ CellTag === 'th' ? scope : undefined }\n\t\t\t\t\t\t\t\tcolSpan={ colspan }\n\t\t\t\t\t\t\t\trowSpan={ rowspan }\n\t\t\t\t\t\t\t\tvalue={ content }\n\t\t\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\t\t\tonFocus={ () => {\n\t\t\t\t\t\t\t\t\tsetSelectedCell( {\n\t\t\t\t\t\t\t\t\t\tsectionName: name,\n\t\t\t\t\t\t\t\t\t\trowIndex,\n\t\t\t\t\t\t\t\t\t\tcolumnIndex,\n\t\t\t\t\t\t\t\t\t\ttype: 'cell',\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\taria-label={ cellAriaLabel[ name ] }\n\t\t\t\t\t\t\t\tplaceholder={ placeholder[ name ] }\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</tr>\n\t\t\t) ) }\n\t\t</TSection>\n\t) );\n\n\tconst isEmpty = ! sections.length;\n\n\treturn (\n\t\t<figure { ...useBlockProps( { ref: tableRef } ) }>\n\t\t\t{ ! isEmpty && (\n\t\t\t\t<>\n\t\t\t\t\t<BlockControls group=\"block\">\n\t\t\t\t\t\t<AlignmentControl\n\t\t\t\t\t\t\tlabel={ __( 'Change column alignment' ) }\n\t\t\t\t\t\t\talignmentControls={ ALIGNMENT_CONTROLS }\n\t\t\t\t\t\t\tvalue={ getCellAlignment() }\n\t\t\t\t\t\t\tonChange={ ( nextAlign ) =>\n\t\t\t\t\t\t\t\tonChangeColumnAlignment( nextAlign )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</BlockControls>\n\t\t\t\t\t<BlockControls group=\"other\">\n\t\t\t\t\t\t<ToolbarDropdownMenu\n\t\t\t\t\t\t\thasArrowIndicator\n\t\t\t\t\t\t\ticon={ table }\n\t\t\t\t\t\t\tlabel={ __( 'Edit table' ) }\n\t\t\t\t\t\t\tcontrols={ tableControls }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</BlockControls>\n\t\t\t\t</>\n\t\t\t) }\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody\n\t\t\t\t\ttitle={ __( 'Settings' ) }\n\t\t\t\t\tclassName=\"blocks-table-settings\"\n\t\t\t\t>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tlabel={ __( 'Fixed width table cells' ) }\n\t\t\t\t\t\tchecked={ !! hasFixedLayout }\n\t\t\t\t\t\tonChange={ onChangeFixedLayout }\n\t\t\t\t\t/>\n\t\t\t\t\t{ ! isEmpty && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t\tlabel={ __( 'Header section' ) }\n\t\t\t\t\t\t\t\tchecked={ !! ( head && head.length ) }\n\t\t\t\t\t\t\t\tonChange={ onToggleHeaderSection }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t\tlabel={ __( 'Footer section' ) }\n\t\t\t\t\t\t\t\tchecked={ !! ( foot && foot.length ) }\n\t\t\t\t\t\t\t\tonChange={ onToggleFooterSection }\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</PanelBody>\n\t\t\t</InspectorControls>\n\t\t\t{ ! isEmpty && (\n\t\t\t\t<table\n\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\tcolorProps.className,\n\t\t\t\t\t\tborderProps.className,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t'has-fixed-layout': hasFixedLayout,\n\t\t\t\t\t\t\t// This is required in the editor only to overcome\n\t\t\t\t\t\t\t// the fact the editor rewrites individual border\n\t\t\t\t\t\t\t// widths into a shorthand format.\n\t\t\t\t\t\t\t'has-individual-borders': hasSplitBorders(\n\t\t\t\t\t\t\t\tattributes?.style?.border\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\tstyle={ { ...colorProps.style, ...borderProps.style } }\n\t\t\t\t>\n\t\t\t\t\t{ renderedSections }\n\t\t\t\t</table>\n\t\t\t) }\n\t\t\t{ ! isEmpty && (\n\t\t\t\t<RichText\n\t\t\t\t\tidentifier=\"caption\"\n\t\t\t\t\ttagName=\"figcaption\"\n\t\t\t\t\tclassName={ __experimentalGetElementClassName( 'caption' ) }\n\t\t\t\t\taria-label={ __( 'Table caption text' ) }\n\t\t\t\t\tplaceholder={ __( 'Add caption' ) }\n\t\t\t\t\tvalue={ caption }\n\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\tsetAttributes( { caption: value } )\n\t\t\t\t\t}\n\t\t\t\t\t// Deselect the selected table cell when the caption is focused.\n\t\t\t\t\tonFocus={ () => setSelectedCell() }\n\t\t\t\t\t__unstableOnSplitAtEnd={ () =>\n\t\t\t\t\t\tinsertBlocksAfter(\n\t\t\t\t\t\t\tcreateBlock( getDefaultBlockName() )\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ isEmpty && (\n\t\t\t\t<Placeholder\n\t\t\t\t\tlabel={ __( 'Table' ) }\n\t\t\t\t\ticon={ <BlockIcon icon={ icon } showColors /> }\n\t\t\t\t\tinstructions={ __( 'Insert a table for sharing data.' ) }\n\t\t\t\t>\n\t\t\t\t\t<form\n\t\t\t\t\t\tclassName=\"blocks-table__placeholder-form\"\n\t\t\t\t\t\tonSubmit={ onCreateTable }\n\t\t\t\t\t>\n\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\t\tlabel={ __( 'Column count' ) }\n\t\t\t\t\t\t\tvalue={ initialColumnCount }\n\t\t\t\t\t\t\tonChange={ onChangeInitialColumnCount }\n\t\t\t\t\t\t\tmin=\"1\"\n\t\t\t\t\t\t\tclassName=\"blocks-table__placeholder-input\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\t\tlabel={ __( 'Row count' ) }\n\t\t\t\t\t\t\tvalue={ initialRowCount }\n\t\t\t\t\t\t\tonChange={ onChangeInitialRowCount }\n\t\t\t\t\t\t\tmin=\"1\"\n\t\t\t\t\t\t\tclassName=\"blocks-table__placeholder-input\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tclassName=\"blocks-table__placeholder-button\"\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Create Table' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</form>\n\t\t\t\t</Placeholder>\n\t\t\t) }\n\t\t</figure>\n\t);\n}\n\nexport default TableEdit;\n"],"mappings":";;;;;;;AAQA,IAAAA,QAAA,GAAAC,OAAA;AALA,IAAAC,WAAA,GAAAC,sBAAA,CAAAF,OAAA;AAMA,IAAAG,YAAA,GAAAH,OAAA;AAWA,IAAAI,KAAA,GAAAJ,OAAA;AACA,IAAAK,WAAA,GAAAL,OAAA;AASA,IAAAM,MAAA,GAAAN,OAAA;AAaA,IAAAO,OAAA,GAAAP,OAAA;AAKA,IAAAQ,MAAA,GAAAR,OAAA;AAhDA;AACA;AACA;;AAGA;AACA;AACA;;AAsCA;AACA;AACA;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/I,QAAE,EAAE,kCAAmC;EAAG,GAEzD,IAAAd,QAAA,CAAA2B,aAAA;IACC4F,SAAS,EAAC,gCAAgC;IAC1CuC,QAAQ,EAAGzG;EAAe,GAE1B,IAAArD,QAAA,CAAA2B,aAAA,EAACrB,WAAA,CAAAyJ,WAAW;IACXf,uBAAuB;IACvB7E,IAAI,EAAC,QAAQ;IACbmE,KAAK,EAAG,IAAAxH,QAAE,EAAE,cAAe,CAAG;IAC9B8G,KAAK,EAAGtF,kBAAoB;IAC5BuB,QAAQ,EAAGX,0BAA4B;IACvC8G,GAAG,EAAC,GAAG;IACPzC,SAAS,EAAC;EAAiC,CAC3C,CAAC,EACF,IAAAvH,QAAA,CAAA2B,aAAA,EAACrB,WAAA,CAAAyJ,WAAW;IACXf,uBAAuB;IACvB7E,IAAI,EAAC,QAAQ;IACbmE,KAAK,EAAG,IAAAxH,QAAE,EAAE,WAAY,CAAG;IAC3B8G,KAAK,EAAGzF,eAAiB;IACzB0B,QAAQ,EAAGT,uBAAyB;IACpC4G,GAAG,EAAC,GAAG;IACPzC,SAAS,EAAC;EAAiC,CAC3C,CAAC,EACF,IAAAvH,QAAA,CAAA2B,aAAA,EAACrB,WAAA,CAAA2J,MAAM;IACN1C,SAAS,EAAC,kCAAkC;IAC5C2C,OAAO,EAAC,SAAS;IACjB/F,IAAI,EAAC;EAAQ,GAEX,IAAArD,QAAE,EAAE,cAAe,CACd,CACH,CACM,CAEP,CAAC;AAEX;AAAC,IAAAqJ,QAAA,GAEcvI,SAAS;AAAAwI,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
1
+ {"version":3,"names":["_element","require","_classnames","_interopRequireDefault","_blockEditor","_i18n","_components","_icons","_blocks","_state","ALIGNMENT_CONTROLS","icon","alignLeft","title","__","align","alignCenter","alignRight","cellAriaLabel","head","body","foot","placeholder","TSection","name","props","TagName","createElement","TableEdit","attributes","setAttributes","insertBlocksAfter","isSelected","hasFixedLayout","caption","initialRowCount","setInitialRowCount","useState","initialColumnCount","setInitialColumnCount","selectedCell","setSelectedCell","colorProps","useColorProps","borderProps","useBorderProps","tableRef","useRef","hasTableCreated","setHasTableCreated","onChangeInitialColumnCount","count","onChangeInitialRowCount","onCreateTable","event","preventDefault","createTable","rowCount","parseInt","columnCount","onChangeFixedLayout","onChange","content","updateSelectedCell","cellAttributes","onChangeColumnAlignment","columnSelection","type","columnIndex","newAttributes","getCellAlignment","getCellAttribute","onToggleHeaderSection","toggleSection","onToggleFooterSection","onInsertRow","delta","sectionName","rowIndex","newRowIndex","insertRow","onInsertRowBefore","onInsertRowAfter","onDeleteRow","deleteRow","onInsertColumn","newColumnIndex","insertColumn","onInsertColumnBefore","onInsertColumnAfter","onDeleteColumn","deleteColumn","useEffect","current","querySelector","focus","sections","filter","isEmptyTableSection","tableControls","tableRowBefore","isDisabled","onClick","tableRowAfter","tableRowDelete","tableColumnBefore","tableColumnAfter","tableColumnDelete","renderedSections","map","key","cells","tag","CellTag","scope","colspan","rowspan","undefined","colSpan","rowSpan","className","classnames","RichText","value","onFocus","isEmpty","length","useBlockProps","ref","Fragment","BlockControls","group","AlignmentControl","label","alignmentControls","nextAlign","ToolbarDropdownMenu","hasArrowIndicator","table","controls","InspectorControls","PanelBody","ToggleControl","__nextHasNoMarginBottom","checked","hasSplitBorders","style","border","identifier","tagName","__experimentalGetElementClassName","__unstableOnSplitAtEnd","createBlock","getDefaultBlockName","Placeholder","BlockIcon","showColors","instructions","onSubmit","TextControl","min","Button","variant","_default","exports","default"],"sources":["@wordpress/block-library/src/table/edit.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useEffect, useRef, useState } from '@wordpress/element';\nimport {\n\tInspectorControls,\n\tBlockControls,\n\tRichText,\n\tBlockIcon,\n\tAlignmentControl,\n\tuseBlockProps,\n\t__experimentalUseColorProps as useColorProps,\n\t__experimentalUseBorderProps as useBorderProps,\n\t__experimentalGetElementClassName,\n} from '@wordpress/block-editor';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tButton,\n\tPanelBody,\n\tPlaceholder,\n\tTextControl,\n\tToggleControl,\n\tToolbarDropdownMenu,\n\t__experimentalHasSplitBorders as hasSplitBorders,\n} from '@wordpress/components';\nimport {\n\talignLeft,\n\talignRight,\n\talignCenter,\n\tblockTable as icon,\n\ttableColumnAfter,\n\ttableColumnBefore,\n\ttableColumnDelete,\n\ttableRowAfter,\n\ttableRowBefore,\n\ttableRowDelete,\n\ttable,\n} from '@wordpress/icons';\nimport { createBlock, getDefaultBlockName } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport {\n\tcreateTable,\n\tupdateSelectedCell,\n\tgetCellAttribute,\n\tinsertRow,\n\tdeleteRow,\n\tinsertColumn,\n\tdeleteColumn,\n\ttoggleSection,\n\tisEmptyTableSection,\n} from './state';\n\nconst ALIGNMENT_CONTROLS = [\n\t{\n\t\ticon: alignLeft,\n\t\ttitle: __( 'Align column left' ),\n\t\talign: 'left',\n\t},\n\t{\n\t\ticon: alignCenter,\n\t\ttitle: __( 'Align column center' ),\n\t\talign: 'center',\n\t},\n\t{\n\t\ticon: alignRight,\n\t\ttitle: __( 'Align column right' ),\n\t\talign: 'right',\n\t},\n];\n\nconst cellAriaLabel = {\n\thead: __( 'Header cell text' ),\n\tbody: __( 'Body cell text' ),\n\tfoot: __( 'Footer cell text' ),\n};\n\nconst placeholder = {\n\thead: __( 'Header label' ),\n\tfoot: __( 'Footer label' ),\n};\n\nfunction TSection( { name, ...props } ) {\n\tconst TagName = `t${ name }`;\n\treturn <TagName { ...props } />;\n}\n\nfunction TableEdit( {\n\tattributes,\n\tsetAttributes,\n\tinsertBlocksAfter,\n\tisSelected,\n} ) {\n\tconst { hasFixedLayout, caption, head, foot } = attributes;\n\tconst [ initialRowCount, setInitialRowCount ] = useState( 2 );\n\tconst [ initialColumnCount, setInitialColumnCount ] = useState( 2 );\n\tconst [ selectedCell, setSelectedCell ] = useState();\n\n\tconst colorProps = useColorProps( attributes );\n\tconst borderProps = useBorderProps( attributes );\n\n\tconst tableRef = useRef();\n\tconst [ hasTableCreated, setHasTableCreated ] = useState( false );\n\n\t/**\n\t * Updates the initial column count used for table creation.\n\t *\n\t * @param {number} count New initial column count.\n\t */\n\tfunction onChangeInitialColumnCount( count ) {\n\t\tsetInitialColumnCount( count );\n\t}\n\n\t/**\n\t * Updates the initial row count used for table creation.\n\t *\n\t * @param {number} count New initial row count.\n\t */\n\tfunction onChangeInitialRowCount( count ) {\n\t\tsetInitialRowCount( count );\n\t}\n\n\t/**\n\t * Creates a table based on dimensions in local state.\n\t *\n\t * @param {Object} event Form submit event.\n\t */\n\tfunction onCreateTable( event ) {\n\t\tevent.preventDefault();\n\n\t\tsetAttributes(\n\t\t\tcreateTable( {\n\t\t\t\trowCount: parseInt( initialRowCount, 10 ) || 2,\n\t\t\t\tcolumnCount: parseInt( initialColumnCount, 10 ) || 2,\n\t\t\t} )\n\t\t);\n\t\tsetHasTableCreated( true );\n\t}\n\n\t/**\n\t * Toggles whether the table has a fixed layout or not.\n\t */\n\tfunction onChangeFixedLayout() {\n\t\tsetAttributes( { hasFixedLayout: ! hasFixedLayout } );\n\t}\n\n\t/**\n\t * Changes the content of the currently selected cell.\n\t *\n\t * @param {Array} content A RichText content value.\n\t */\n\tfunction onChange( content ) {\n\t\tif ( ! selectedCell ) {\n\t\t\treturn;\n\t\t}\n\n\t\tsetAttributes(\n\t\t\tupdateSelectedCell(\n\t\t\t\tattributes,\n\t\t\t\tselectedCell,\n\t\t\t\t( cellAttributes ) => ( {\n\t\t\t\t\t...cellAttributes,\n\t\t\t\t\tcontent,\n\t\t\t\t} )\n\t\t\t)\n\t\t);\n\t}\n\n\t/**\n\t * Align text within the a column.\n\t *\n\t * @param {string} align The new alignment to apply to the column.\n\t */\n\tfunction onChangeColumnAlignment( align ) {\n\t\tif ( ! selectedCell ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Convert the cell selection to a column selection so that alignment\n\t\t// is applied to the entire column.\n\t\tconst columnSelection = {\n\t\t\ttype: 'column',\n\t\t\tcolumnIndex: selectedCell.columnIndex,\n\t\t};\n\n\t\tconst newAttributes = updateSelectedCell(\n\t\t\tattributes,\n\t\t\tcolumnSelection,\n\t\t\t( cellAttributes ) => ( {\n\t\t\t\t...cellAttributes,\n\t\t\t\talign,\n\t\t\t} )\n\t\t);\n\t\tsetAttributes( newAttributes );\n\t}\n\n\t/**\n\t * Get the alignment of the currently selected cell.\n\t *\n\t * @return {string | undefined} The new alignment to apply to the column.\n\t */\n\tfunction getCellAlignment() {\n\t\tif ( ! selectedCell ) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn getCellAttribute( attributes, selectedCell, 'align' );\n\t}\n\n\t/**\n\t * Add or remove a `head` table section.\n\t */\n\tfunction onToggleHeaderSection() {\n\t\tsetAttributes( toggleSection( attributes, 'head' ) );\n\t}\n\n\t/**\n\t * Add or remove a `foot` table section.\n\t */\n\tfunction onToggleFooterSection() {\n\t\tsetAttributes( toggleSection( attributes, 'foot' ) );\n\t}\n\n\t/**\n\t * Inserts a row at the currently selected row index, plus `delta`.\n\t *\n\t * @param {number} delta Offset for selected row index at which to insert.\n\t */\n\tfunction onInsertRow( delta ) {\n\t\tif ( ! selectedCell ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { sectionName, rowIndex } = selectedCell;\n\t\tconst newRowIndex = rowIndex + delta;\n\n\t\tsetAttributes(\n\t\t\tinsertRow( attributes, {\n\t\t\t\tsectionName,\n\t\t\t\trowIndex: newRowIndex,\n\t\t\t} )\n\t\t);\n\t\t// Select the first cell of the new row.\n\t\tsetSelectedCell( {\n\t\t\tsectionName,\n\t\t\trowIndex: newRowIndex,\n\t\t\tcolumnIndex: 0,\n\t\t\ttype: 'cell',\n\t\t} );\n\t}\n\n\t/**\n\t * Inserts a row before the currently selected row.\n\t */\n\tfunction onInsertRowBefore() {\n\t\tonInsertRow( 0 );\n\t}\n\n\t/**\n\t * Inserts a row after the currently selected row.\n\t */\n\tfunction onInsertRowAfter() {\n\t\tonInsertRow( 1 );\n\t}\n\n\t/**\n\t * Deletes the currently selected row.\n\t */\n\tfunction onDeleteRow() {\n\t\tif ( ! selectedCell ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { sectionName, rowIndex } = selectedCell;\n\n\t\tsetSelectedCell();\n\t\tsetAttributes( deleteRow( attributes, { sectionName, rowIndex } ) );\n\t}\n\n\t/**\n\t * Inserts a column at the currently selected column index, plus `delta`.\n\t *\n\t * @param {number} delta Offset for selected column index at which to insert.\n\t */\n\tfunction onInsertColumn( delta = 0 ) {\n\t\tif ( ! selectedCell ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { columnIndex } = selectedCell;\n\t\tconst newColumnIndex = columnIndex + delta;\n\n\t\tsetAttributes(\n\t\t\tinsertColumn( attributes, {\n\t\t\t\tcolumnIndex: newColumnIndex,\n\t\t\t} )\n\t\t);\n\t\t// Select the first cell of the new column.\n\t\tsetSelectedCell( {\n\t\t\trowIndex: 0,\n\t\t\tcolumnIndex: newColumnIndex,\n\t\t\ttype: 'cell',\n\t\t} );\n\t}\n\n\t/**\n\t * Inserts a column before the currently selected column.\n\t */\n\tfunction onInsertColumnBefore() {\n\t\tonInsertColumn( 0 );\n\t}\n\n\t/**\n\t * Inserts a column after the currently selected column.\n\t */\n\tfunction onInsertColumnAfter() {\n\t\tonInsertColumn( 1 );\n\t}\n\n\t/**\n\t * Deletes the currently selected column.\n\t */\n\tfunction onDeleteColumn() {\n\t\tif ( ! selectedCell ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { sectionName, columnIndex } = selectedCell;\n\n\t\tsetSelectedCell();\n\t\tsetAttributes(\n\t\t\tdeleteColumn( attributes, { sectionName, columnIndex } )\n\t\t);\n\t}\n\n\tuseEffect( () => {\n\t\tif ( ! isSelected ) {\n\t\t\tsetSelectedCell();\n\t\t}\n\t}, [ isSelected ] );\n\n\tuseEffect( () => {\n\t\tif ( hasTableCreated ) {\n\t\t\ttableRef?.current\n\t\t\t\t?.querySelector( 'td div[contentEditable=\"true\"]' )\n\t\t\t\t?.focus();\n\t\t\tsetHasTableCreated( false );\n\t\t}\n\t}, [ hasTableCreated ] );\n\n\tconst sections = [ 'head', 'body', 'foot' ].filter(\n\t\t( name ) => ! isEmptyTableSection( attributes[ name ] )\n\t);\n\n\tconst tableControls = [\n\t\t{\n\t\t\ticon: tableRowBefore,\n\t\t\ttitle: __( 'Insert row before' ),\n\t\t\tisDisabled: ! selectedCell,\n\t\t\tonClick: onInsertRowBefore,\n\t\t},\n\t\t{\n\t\t\ticon: tableRowAfter,\n\t\t\ttitle: __( 'Insert row after' ),\n\t\t\tisDisabled: ! selectedCell,\n\t\t\tonClick: onInsertRowAfter,\n\t\t},\n\t\t{\n\t\t\ticon: tableRowDelete,\n\t\t\ttitle: __( 'Delete row' ),\n\t\t\tisDisabled: ! selectedCell,\n\t\t\tonClick: onDeleteRow,\n\t\t},\n\t\t{\n\t\t\ticon: tableColumnBefore,\n\t\t\ttitle: __( 'Insert column before' ),\n\t\t\tisDisabled: ! selectedCell,\n\t\t\tonClick: onInsertColumnBefore,\n\t\t},\n\t\t{\n\t\t\ticon: tableColumnAfter,\n\t\t\ttitle: __( 'Insert column after' ),\n\t\t\tisDisabled: ! selectedCell,\n\t\t\tonClick: onInsertColumnAfter,\n\t\t},\n\t\t{\n\t\t\ticon: tableColumnDelete,\n\t\t\ttitle: __( 'Delete column' ),\n\t\t\tisDisabled: ! selectedCell,\n\t\t\tonClick: onDeleteColumn,\n\t\t},\n\t];\n\n\tconst renderedSections = sections.map( ( name ) => (\n\t\t<TSection name={ name } key={ name }>\n\t\t\t{ attributes[ name ].map( ( { cells }, rowIndex ) => (\n\t\t\t\t<tr key={ rowIndex }>\n\t\t\t\t\t{ cells.map(\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcontent,\n\t\t\t\t\t\t\t\ttag: CellTag,\n\t\t\t\t\t\t\t\tscope,\n\t\t\t\t\t\t\t\talign,\n\t\t\t\t\t\t\t\tcolspan,\n\t\t\t\t\t\t\t\trowspan,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tcolumnIndex\n\t\t\t\t\t\t) => (\n\t\t\t\t\t\t\t<CellTag\n\t\t\t\t\t\t\t\tkey={ columnIndex }\n\t\t\t\t\t\t\t\tscope={ CellTag === 'th' ? scope : undefined }\n\t\t\t\t\t\t\t\tcolSpan={ colspan }\n\t\t\t\t\t\t\t\trowSpan={ rowspan }\n\t\t\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t[ `has-text-align-${ align }` ]: align,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t'wp-block-table__cell-content'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<RichText\n\t\t\t\t\t\t\t\t\tvalue={ content }\n\t\t\t\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\t\t\t\tonFocus={ () => {\n\t\t\t\t\t\t\t\t\t\tsetSelectedCell( {\n\t\t\t\t\t\t\t\t\t\t\tsectionName: name,\n\t\t\t\t\t\t\t\t\t\t\trowIndex,\n\t\t\t\t\t\t\t\t\t\t\tcolumnIndex,\n\t\t\t\t\t\t\t\t\t\t\ttype: 'cell',\n\t\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\taria-label={ cellAriaLabel[ name ] }\n\t\t\t\t\t\t\t\t\tplaceholder={ placeholder[ name ] }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</CellTag>\n\t\t\t\t\t\t)\n\t\t\t\t\t) }\n\t\t\t\t</tr>\n\t\t\t) ) }\n\t\t</TSection>\n\t) );\n\n\tconst isEmpty = ! sections.length;\n\n\treturn (\n\t\t<figure { ...useBlockProps( { ref: tableRef } ) }>\n\t\t\t{ ! isEmpty && (\n\t\t\t\t<>\n\t\t\t\t\t<BlockControls group=\"block\">\n\t\t\t\t\t\t<AlignmentControl\n\t\t\t\t\t\t\tlabel={ __( 'Change column alignment' ) }\n\t\t\t\t\t\t\talignmentControls={ ALIGNMENT_CONTROLS }\n\t\t\t\t\t\t\tvalue={ getCellAlignment() }\n\t\t\t\t\t\t\tonChange={ ( nextAlign ) =>\n\t\t\t\t\t\t\t\tonChangeColumnAlignment( nextAlign )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</BlockControls>\n\t\t\t\t\t<BlockControls group=\"other\">\n\t\t\t\t\t\t<ToolbarDropdownMenu\n\t\t\t\t\t\t\thasArrowIndicator\n\t\t\t\t\t\t\ticon={ table }\n\t\t\t\t\t\t\tlabel={ __( 'Edit table' ) }\n\t\t\t\t\t\t\tcontrols={ tableControls }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</BlockControls>\n\t\t\t\t</>\n\t\t\t) }\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody\n\t\t\t\t\ttitle={ __( 'Settings' ) }\n\t\t\t\t\tclassName=\"blocks-table-settings\"\n\t\t\t\t>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tlabel={ __( 'Fixed width table cells' ) }\n\t\t\t\t\t\tchecked={ !! hasFixedLayout }\n\t\t\t\t\t\tonChange={ onChangeFixedLayout }\n\t\t\t\t\t/>\n\t\t\t\t\t{ ! isEmpty && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t\tlabel={ __( 'Header section' ) }\n\t\t\t\t\t\t\t\tchecked={ !! ( head && head.length ) }\n\t\t\t\t\t\t\t\tonChange={ onToggleHeaderSection }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t\tlabel={ __( 'Footer section' ) }\n\t\t\t\t\t\t\t\tchecked={ !! ( foot && foot.length ) }\n\t\t\t\t\t\t\t\tonChange={ onToggleFooterSection }\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</PanelBody>\n\t\t\t</InspectorControls>\n\t\t\t{ ! isEmpty && (\n\t\t\t\t<table\n\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\tcolorProps.className,\n\t\t\t\t\t\tborderProps.className,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t'has-fixed-layout': hasFixedLayout,\n\t\t\t\t\t\t\t// This is required in the editor only to overcome\n\t\t\t\t\t\t\t// the fact the editor rewrites individual border\n\t\t\t\t\t\t\t// widths into a shorthand format.\n\t\t\t\t\t\t\t'has-individual-borders': hasSplitBorders(\n\t\t\t\t\t\t\t\tattributes?.style?.border\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\tstyle={ { ...colorProps.style, ...borderProps.style } }\n\t\t\t\t>\n\t\t\t\t\t{ renderedSections }\n\t\t\t\t</table>\n\t\t\t) }\n\t\t\t{ ! isEmpty && (\n\t\t\t\t<RichText\n\t\t\t\t\tidentifier=\"caption\"\n\t\t\t\t\ttagName=\"figcaption\"\n\t\t\t\t\tclassName={ __experimentalGetElementClassName( 'caption' ) }\n\t\t\t\t\taria-label={ __( 'Table caption text' ) }\n\t\t\t\t\tplaceholder={ __( 'Add caption' ) }\n\t\t\t\t\tvalue={ caption }\n\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\tsetAttributes( { caption: value } )\n\t\t\t\t\t}\n\t\t\t\t\t// Deselect the selected table cell when the caption is focused.\n\t\t\t\t\tonFocus={ () => setSelectedCell() }\n\t\t\t\t\t__unstableOnSplitAtEnd={ () =>\n\t\t\t\t\t\tinsertBlocksAfter(\n\t\t\t\t\t\t\tcreateBlock( getDefaultBlockName() )\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ isEmpty && (\n\t\t\t\t<Placeholder\n\t\t\t\t\tlabel={ __( 'Table' ) }\n\t\t\t\t\ticon={ <BlockIcon icon={ icon } showColors /> }\n\t\t\t\t\tinstructions={ __( 'Insert a table for sharing data.' ) }\n\t\t\t\t>\n\t\t\t\t\t<form\n\t\t\t\t\t\tclassName=\"blocks-table__placeholder-form\"\n\t\t\t\t\t\tonSubmit={ onCreateTable }\n\t\t\t\t\t>\n\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\t\tlabel={ __( 'Column count' ) }\n\t\t\t\t\t\t\tvalue={ initialColumnCount }\n\t\t\t\t\t\t\tonChange={ onChangeInitialColumnCount }\n\t\t\t\t\t\t\tmin=\"1\"\n\t\t\t\t\t\t\tclassName=\"blocks-table__placeholder-input\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\t\tlabel={ __( 'Row count' ) }\n\t\t\t\t\t\t\tvalue={ initialRowCount }\n\t\t\t\t\t\t\tonChange={ onChangeInitialRowCount }\n\t\t\t\t\t\t\tmin=\"1\"\n\t\t\t\t\t\t\tclassName=\"blocks-table__placeholder-input\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tclassName=\"blocks-table__placeholder-button\"\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Create Table' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</form>\n\t\t\t\t</Placeholder>\n\t\t\t) }\n\t\t</figure>\n\t);\n}\n\nexport default TableEdit;\n"],"mappings":";;;;;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H,CACM,CAEP,CAAC;AAEX;AAAC,IAAAqJ,QAAA,GAEcvI,SAAS;AAAAwI,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
@@ -6,21 +6,15 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = TableOfContentsEdit;
8
8
  var _element = require("@wordpress/element");
9
- var _es = _interopRequireDefault(require("fast-deep-equal/es6"));
10
9
  var _blockEditor = require("@wordpress/block-editor");
11
10
  var _blocks = require("@wordpress/blocks");
12
11
  var _components = require("@wordpress/components");
13
12
  var _data = require("@wordpress/data");
14
- var _dom = require("@wordpress/dom");
15
13
  var _i18n = require("@wordpress/i18n");
16
- var _url = require("@wordpress/url");
17
14
  var _icon = _interopRequireDefault(require("./icon"));
18
15
  var _list = _interopRequireDefault(require("./list"));
19
16
  var _utils = require("./utils");
20
- /**
21
- * External dependencies
22
- */
23
-
17
+ var _hooks = require("./hooks");
24
18
  /**
25
19
  * WordPress dependencies
26
20
  */
@@ -51,6 +45,7 @@ function TableOfContentsEdit({
51
45
  clientId,
52
46
  setAttributes
53
47
  }) {
48
+ (0, _hooks.useObserveHeadings)(clientId);
54
49
  const blockProps = (0, _blockEditor.useBlockProps)();
55
50
  const canInsertList = (0, _data.useSelect)(select => {
56
51
  const {
@@ -61,131 +56,8 @@ function TableOfContentsEdit({
61
56
  return canInsertBlockType('core/list', rootClientId);
62
57
  }, [clientId]);
63
58
  const {
64
- __unstableMarkNextChangeAsNotPersistent,
65
59
  replaceBlocks
66
60
  } = (0, _data.useDispatch)(_blockEditor.store);
67
-
68
- /**
69
- * The latest heading data, or null if the new data deeply equals the saved
70
- * headings attribute.
71
- *
72
- * Since useSelect forces a re-render when its return value is shallowly
73
- * inequal to its prior call, we would be re-rendering this block every time
74
- * the stores change, even if the latest headings were deeply equal to the
75
- * ones saved in the block attributes.
76
- *
77
- * By returning null when they're equal, we reduce that to 2 renders: one
78
- * when there are new latest headings (and so it returns them), and one when
79
- * they haven't changed (so it returns null). As long as the latest heading
80
- * data remains the same, further calls of the useSelect callback will
81
- * continue to return null, thus preventing any forced re-renders.
82
- */
83
- const latestHeadings = (0, _data.useSelect)(select => {
84
- var _editorSelectors$getP;
85
- const {
86
- getBlockAttributes,
87
- getBlockName,
88
- getClientIdsWithDescendants,
89
- __experimentalGetGlobalBlocksByName: getGlobalBlocksByName
90
- } = select(_blockEditor.store);
91
-
92
- // FIXME: @wordpress/block-library should not depend on @wordpress/editor.
93
- // Blocks can be loaded into a *non-post* block editor, so to avoid
94
- // declaring @wordpress/editor as a dependency, we must access its
95
- // store by string. When the store is not available, editorSelectors
96
- // will be null, and the block's saved markup will lack permalinks.
97
- // eslint-disable-next-line @wordpress/data-no-store-string-literals
98
- const editorSelectors = select('core/editor');
99
- const pageBreakClientIds = getGlobalBlocksByName('core/nextpage');
100
- const isPaginated = pageBreakClientIds.length !== 0;
101
-
102
- // Get the client ids of all blocks in the editor.
103
- const allBlockClientIds = getClientIdsWithDescendants();
104
-
105
- // 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.
106
- let tocPage = 1;
107
- if (isPaginated && onlyIncludeCurrentPage) {
108
- // We can't use getBlockIndex because it only returns the index
109
- // relative to sibling blocks.
110
- const tocIndex = allBlockClientIds.indexOf(clientId);
111
- for (const [blockIndex, blockClientId] of allBlockClientIds.entries()) {
112
- // If we've reached blocks after the Table of Contents, we've
113
- // finished calculating which page the block is on.
114
- if (blockIndex >= tocIndex) {
115
- break;
116
- }
117
- if (getBlockName(blockClientId) === 'core/nextpage') {
118
- tocPage++;
119
- }
120
- }
121
- }
122
- const _latestHeadings = [];
123
-
124
- /** The page (of a paginated post) a heading will be part of. */
125
- let headingPage = 1;
126
-
127
- /**
128
- * A permalink to the current post. If the core/editor store is
129
- * unavailable, this variable will be null.
130
- */
131
- const permalink = (_editorSelectors$getP = editorSelectors?.getPermalink()) !== null && _editorSelectors$getP !== void 0 ? _editorSelectors$getP : null;
132
- let headingPageLink = null;
133
-
134
- // If the core/editor store is available, we can add permalinks to the
135
- // generated table of contents.
136
- if (typeof permalink === 'string') {
137
- headingPageLink = isPaginated ? (0, _url.addQueryArgs)(permalink, {
138
- page: headingPage
139
- }) : permalink;
140
- }
141
- for (const blockClientId of allBlockClientIds) {
142
- const blockName = getBlockName(blockClientId);
143
- if (blockName === 'core/nextpage') {
144
- headingPage++;
145
-
146
- // If we're only including headings from the current page (of
147
- // a paginated post), then exit the loop if we've reached the
148
- // pages after the one with the Table of Contents block.
149
- if (onlyIncludeCurrentPage && headingPage > tocPage) {
150
- break;
151
- }
152
- if (typeof permalink === 'string') {
153
- headingPageLink = (0, _url.addQueryArgs)((0, _url.removeQueryArgs)(permalink, ['page']), {
154
- page: headingPage
155
- });
156
- }
157
- }
158
- // If we're including all headings or we've reached headings on
159
- // the same page as the Table of Contents block, add them to the
160
- // list.
161
- else if (!onlyIncludeCurrentPage || headingPage === tocPage) {
162
- if (blockName === 'core/heading') {
163
- const headingAttributes = getBlockAttributes(blockClientId);
164
- const canBeLinked = typeof headingPageLink === 'string' && typeof headingAttributes.anchor === 'string' && headingAttributes.anchor !== '';
165
- _latestHeadings.push({
166
- // Convert line breaks to spaces, and get rid of HTML tags in the headings.
167
- content: (0, _dom.__unstableStripHTML)(headingAttributes.content.replace(/(<br *\/?>)+/g, ' ')),
168
- level: headingAttributes.level,
169
- link: canBeLinked ? `${headingPageLink}#${headingAttributes.anchor}` : null
170
- });
171
- }
172
- }
173
- }
174
- if ((0, _es.default)(headings, _latestHeadings)) {
175
- return null;
176
- }
177
- return _latestHeadings;
178
- }, [clientId, onlyIncludeCurrentPage, headings]);
179
- (0, _element.useEffect)(() => {
180
- if (latestHeadings !== null) {
181
- // This is required to keep undo working and not create 2 undo steps
182
- // for each heading change.
183
- __unstableMarkNextChangeAsNotPersistent();
184
- setAttributes({
185
- headings: latestHeadings
186
- });
187
- }
188
- }, [latestHeadings]);
189
61
  const headingTree = (0, _utils.linearToNestedHeadingList)(headings);
190
62
  const toolbarControls = canInsertList && (0, _element.createElement)(_blockEditor.BlockControls, null, (0, _element.createElement)(_components.ToolbarGroup, null, (0, _element.createElement)(_components.ToolbarButton, {
191
63
  onClick: () => replaceBlocks(clientId, (0, _blocks.createBlock)('core/list', {
@@ -1 +1 @@
1
- {"version":3,"names":["_element","require","_es","_interopRequireDefault","_blockEditor","_blocks","_components","_data","_dom","_i18n","_url","_icon","_list","_utils","TableOfContentsEdit","attributes","headings","onlyIncludeCurrentPage","clientId","setAttributes","blockProps","useBlockProps","canInsertList","useSelect","select","getBlockRootClientId","canInsertBlockType","blockEditorStore","rootClientId","__unstableMarkNextChangeAsNotPersistent","replaceBlocks","useDispatch","latestHeadings","_editorSelectors$getP","getBlockAttributes","getBlockName","getClientIdsWithDescendants","__experimentalGetGlobalBlocksByName","getGlobalBlocksByName","editorSelectors","pageBreakClientIds","isPaginated","length","allBlockClientIds","tocPage","tocIndex","indexOf","blockIndex","blockClientId","entries","_latestHeadings","headingPage","permalink","getPermalink","headingPageLink","addQueryArgs","page","blockName","removeQueryArgs","headingAttributes","canBeLinked","anchor","push","content","stripHTML","replace","level","link","fastDeepEqual","useEffect","headingTree","linearToNestedHeadingList","toolbarControls","createElement","BlockControls","ToolbarGroup","ToolbarButton","onClick","createBlock","ordered","values","renderToString","default","nestedHeadingList","__","inspectorControls","InspectorControls","PanelBody","title","ToggleControl","__nextHasNoMarginBottom","label","checked","onChange","value","help","Fragment","Placeholder","icon","BlockIcon","instructions","inert"],"sources":["@wordpress/block-library/src/table-of-contents/edit.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6';\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 } 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 { __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\n\tconst canInsertList = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlockRootClientId, canInsertBlockType } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst rootClientId = getBlockRootClientId( clientId );\n\n\t\t\treturn canInsertBlockType( 'core/list', rootClientId );\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst { __unstableMarkNextChangeAsNotPersistent, replaceBlocks } =\n\t\tuseDispatch( 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 =\n\t\t\t\t\t\t\tgetBlockAttributes( blockClientId );\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\t// Convert line breaks to spaces, and get rid of HTML tags in the headings.\n\t\t\t\t\t\t\tcontent: stripHTML(\n\t\t\t\t\t\t\t\theadingAttributes.content.replace(\n\t\t\t\t\t\t\t\t\t/(<br *\\/?>)+/g,\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\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 ( fastDeepEqual( 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 = canInsertList && (\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\t__nextHasNoMarginBottom\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 inert=\"true\">\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"],"mappings":";;;;;;;AAyBA,IAAAA,QAAA,GAAAC,OAAA;AAtBA,IAAAC,GAAA,GAAAC,sBAAA,CAAAF,OAAA;AAKA,IAAAG,YAAA,GAAAH,OAAA;AAOA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,WAAA,GAAAL,OAAA;AAOA,IAAAM,KAAA,GAAAN,OAAA;AACA,IAAAO,IAAA,GAAAP,OAAA;AAEA,IAAAQ,KAAA,GAAAR,OAAA;AACA,IAAAS,IAAA,GAAAT,OAAA;AAKA,IAAAU,KAAA,GAAAR,sBAAA,CAAAF,OAAA;AACA,IAAAW,KAAA,GAAAT,sBAAA,CAAAF,OAAA;AACA,IAAAY,MAAA,GAAAZ,OAAA;AAlCA;AACA;AACA;;AAGA;AACA;AACA;;AAsBA;AACA;AACA;;AAKA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASa,mBAAmBA,CAAE;EAC5CC,UAAU,EAAE;IAAEC,QAAQ,GAAG,EAAE;IAAEC;EAAuB,CAAC;EACrDC,QAAQ;EACRC;AACD,CAAC,EAAG;EACH,MAAMC,UAAU,GAAG,IAAAC,0BAAa,EAAC,CAAC;EAElC,MAAMC,aAAa,GAAG,IAAAC,eAAS,EAC5BC,MAAM,IAAM;IACb,MAAM;MAAEC,oBAAoB;MAAEC;IAAmB,CAAC,GACjDF,MAAM,CAAEG,kBAAiB,CAAC;IAC3B,MAAMC,YAA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f,IAAArG,QAAA,CAAAyE,aAAA,EAAC7D,KAAA,CAAAsE,OAAmB;IAACC,iBAAiB,EAAGb;EAAa,CAAE,CACrD,CACA,CAAC,EACJE,eAAe,EACfa,iBACD,CAAC;AAEL"}
1
+ {"version":3,"names":["_element","require","_blockEditor","_blocks","_components","_data","_i18n","_icon","_interopRequireDefault","_list","_utils","_hooks","TableOfContentsEdit","attributes","headings","onlyIncludeCurrentPage","clientId","setAttributes","useObserveHeadings","blockProps","useBlockProps","canInsertList","useSelect","select","getBlockRootClientId","canInsertBlockType","blockEditorStore","rootClientId","replaceBlocks","useDispatch","headingTree","linearToNestedHeadingList","toolbarControls","createElement","BlockControls","ToolbarGroup","ToolbarButton","onClick","createBlock","ordered","values","renderToString","default","nestedHeadingList","__","inspectorControls","InspectorControls","PanelBody","title","ToggleControl","__nextHasNoMarginBottom","label","checked","onChange","value","help","length","Fragment","Placeholder","icon","BlockIcon","instructions","inert"],"sources":["@wordpress/block-library/src/table-of-contents/edit.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tBlockControls,\n\tBlockIcon,\n\tInspectorControls,\n\tstore as blockEditorStore,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport { createBlock } 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 } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport icon from './icon';\nimport TableOfContentsList from './list';\nimport { linearToNestedHeadingList } from './utils';\nimport { useObserveHeadings } from './hooks';\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\tuseObserveHeadings( clientId );\n\n\tconst blockProps = useBlockProps();\n\n\tconst canInsertList = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlockRootClientId, canInsertBlockType } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst rootClientId = getBlockRootClientId( clientId );\n\n\t\t\treturn canInsertBlockType( 'core/list', rootClientId );\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst { replaceBlocks } = useDispatch( blockEditorStore );\n\n\tconst headingTree = linearToNestedHeadingList( headings );\n\n\tconst toolbarControls = canInsertList && (\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\t__nextHasNoMarginBottom\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 inert=\"true\">\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"],"mappings":";;;;;;;AAmBA,IAAAA,QAAA,GAAAC,OAAA;AAhBA,IAAAC,YAAA,GAAAD,OAAA;AAOA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AAOA,IAAA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AAK,EAAG,IAAAP,QAAE,EAAE,mBAAoB,CAAG;MACnCiB,YAAY,EAAG,IAAAjB,QAAE,EAChB,4GACD;IAAG,CACH,CACG,CAAC,EACJC,iBACD,CAAC;EAEL;EAEA,OACC,IAAA7C,QAAA,CAAAiC,aAAA,EAAAjC,QAAA,CAAAyD,QAAA,QACC,IAAAzD,QAAA,CAAAiC,aAAA;IAAA,GAAUd;EAAU,GACnB,IAAAnB,QAAA,CAAAiC,aAAA;IAAI6B,KAAK,EAAC;EAAM,GACf,IAAA9D,QAAA,CAAAiC,aAAA,EAACxB,KAAA,CAAAiC,OAAmB;IAACC,iBAAiB,EAAGb;EAAa,CAAE,CACrD,CACA,CAAC,EACJE,eAAe,EACfa,iBACD,CAAC;AAEL"}
@@ -0,0 +1,145 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.useObserveHeadings = useObserveHeadings;
8
+ var _es = _interopRequireDefault(require("fast-deep-equal/es6"));
9
+ var _data = require("@wordpress/data");
10
+ var _dom = require("@wordpress/dom");
11
+ var _element = require("@wordpress/element");
12
+ var _url = require("@wordpress/url");
13
+ var _blockEditor = require("@wordpress/block-editor");
14
+ /**
15
+ * External dependencies
16
+ */
17
+
18
+ /**
19
+ * WordPress dependencies
20
+ */
21
+
22
+ function getLatestHeadings(select, clientId) {
23
+ var _select$getPermalink, _getBlockAttributes;
24
+ const {
25
+ getBlockAttributes,
26
+ getBlockName,
27
+ getClientIdsWithDescendants,
28
+ __experimentalGetGlobalBlocksByName: getGlobalBlocksByName
29
+ } = select(_blockEditor.store);
30
+
31
+ // FIXME: @wordpress/block-library should not depend on @wordpress/editor.
32
+ // Blocks can be loaded into a *non-post* block editor, so to avoid
33
+ // declaring @wordpress/editor as a dependency, we must access its
34
+ // store by string. When the store is not available, editorSelectors
35
+ // will be null, and the block's saved markup will lack permalinks.
36
+ // eslint-disable-next-line @wordpress/data-no-store-string-literals
37
+ const permalink = (_select$getPermalink = select('core/editor').getPermalink()) !== null && _select$getPermalink !== void 0 ? _select$getPermalink : null;
38
+ const isPaginated = getGlobalBlocksByName('core/nextpage').length !== 0;
39
+ const {
40
+ onlyIncludeCurrentPage
41
+ } = (_getBlockAttributes = getBlockAttributes(clientId)) !== null && _getBlockAttributes !== void 0 ? _getBlockAttributes : {};
42
+
43
+ // Get the client ids of all blocks in the editor.
44
+ const allBlockClientIds = getClientIdsWithDescendants();
45
+
46
+ // 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.
47
+ let tocPage = 1;
48
+ if (isPaginated && onlyIncludeCurrentPage) {
49
+ // We can't use getBlockIndex because it only returns the index
50
+ // relative to sibling blocks.
51
+ const tocIndex = allBlockClientIds.indexOf(clientId);
52
+ for (const [blockIndex, blockClientId] of allBlockClientIds.entries()) {
53
+ // If we've reached blocks after the Table of Contents, we've
54
+ // finished calculating which page the block is on.
55
+ if (blockIndex >= tocIndex) {
56
+ break;
57
+ }
58
+ if (getBlockName(blockClientId) === 'core/nextpage') {
59
+ tocPage++;
60
+ }
61
+ }
62
+ }
63
+ const latestHeadings = [];
64
+
65
+ /** The page (of a paginated post) a heading will be part of. */
66
+ let headingPage = 1;
67
+ let headingPageLink = null;
68
+
69
+ // If the core/editor store is available, we can add permalinks to the
70
+ // generated table of contents.
71
+ if (typeof permalink === 'string') {
72
+ headingPageLink = isPaginated ? (0, _url.addQueryArgs)(permalink, {
73
+ page: headingPage
74
+ }) : permalink;
75
+ }
76
+ for (const blockClientId of allBlockClientIds) {
77
+ const blockName = getBlockName(blockClientId);
78
+ if (blockName === 'core/nextpage') {
79
+ headingPage++;
80
+
81
+ // If we're only including headings from the current page (of
82
+ // a paginated post), then exit the loop if we've reached the
83
+ // pages after the one with the Table of Contents block.
84
+ if (onlyIncludeCurrentPage && headingPage > tocPage) {
85
+ break;
86
+ }
87
+ if (typeof permalink === 'string') {
88
+ headingPageLink = (0, _url.addQueryArgs)((0, _url.removeQueryArgs)(permalink, ['page']), {
89
+ page: headingPage
90
+ });
91
+ }
92
+ }
93
+ // If we're including all headings or we've reached headings on
94
+ // the same page as the Table of Contents block, add them to the
95
+ // list.
96
+ else if (!onlyIncludeCurrentPage || headingPage === tocPage) {
97
+ if (blockName === 'core/heading') {
98
+ const headingAttributes = getBlockAttributes(blockClientId);
99
+ const canBeLinked = typeof headingPageLink === 'string' && typeof headingAttributes.anchor === 'string' && headingAttributes.anchor !== '';
100
+ latestHeadings.push({
101
+ // Convert line breaks to spaces, and get rid of HTML tags in the headings.
102
+ content: (0, _dom.__unstableStripHTML)(headingAttributes.content.replace(/(<br *\/?>)+/g, ' ')),
103
+ level: headingAttributes.level,
104
+ link: canBeLinked ? `${headingPageLink}#${headingAttributes.anchor}` : null
105
+ });
106
+ }
107
+ }
108
+ }
109
+ return latestHeadings;
110
+ }
111
+ function observeCallback(select, dispatch, clientId) {
112
+ const {
113
+ getBlockAttributes
114
+ } = select(_blockEditor.store);
115
+ const {
116
+ updateBlockAttributes,
117
+ __unstableMarkNextChangeAsNotPersistent
118
+ } = dispatch(_blockEditor.store);
119
+
120
+ /**
121
+ * If the block no longer exists in the store, skip the update.
122
+ * The "undo" action recreates the block and provides a new `clientId`.
123
+ * The hook still might be observing the changes while the old block unmounts.
124
+ */
125
+ const attributes = getBlockAttributes(clientId);
126
+ if (attributes === null) {
127
+ return;
128
+ }
129
+ const headings = getLatestHeadings(select, clientId);
130
+ if (!(0, _es.default)(headings, attributes.headings)) {
131
+ __unstableMarkNextChangeAsNotPersistent();
132
+ updateBlockAttributes(clientId, {
133
+ headings
134
+ });
135
+ }
136
+ }
137
+ function useObserveHeadings(clientId) {
138
+ const registry = (0, _data.useRegistry)();
139
+ (0, _element.useEffect)(() => {
140
+ // Todo: Limit subscription to block editor store when data no longer depends on `getPermalink`.
141
+ // See: https://github.com/WordPress/gutenberg/pull/45513
142
+ return registry.subscribe(() => observeCallback(registry.select, registry.dispatch, clientId));
143
+ }, [registry, clientId]);
144
+ }
145
+ //# sourceMappingURL=hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_es","_interopRequireDefault","require","_data","_dom","_element","_url","_blockEditor","getLatestHeadings","select","clientId","_select$getPermalink","_getBlockAttributes","getBlockAttributes","getBlockName","getClientIdsWithDescendants","__experimentalGetGlobalBlocksByName","getGlobalBlocksByName","blockEditorStore","permalink","getPermalink","isPaginated","length","onlyIncludeCurrentPage","allBlockClientIds","tocPage","tocIndex","indexOf","blockIndex","blockClientId","entries","latestHeadings","headingPage","headingPageLink","addQueryArgs","page","blockName","removeQueryArgs","headingAttributes","canBeLinked","anchor","push","content","stripHTML","replace","level","link","observeCallback","dispatch","updateBlockAttributes","__unstableMarkNextChangeAsNotPersistent","attributes","headings","fastDeepEqual","useObserveHeadings","registry","useRegistry","useEffect","subscribe"],"sources":["@wordpress/block-library/src/table-of-contents/hooks.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6';\n\n/**\n * WordPress dependencies\n */\nimport { useRegistry } from '@wordpress/data';\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\nimport { useEffect } from '@wordpress/element';\nimport { addQueryArgs, removeQueryArgs } from '@wordpress/url';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\nfunction getLatestHeadings( select, clientId ) {\n\tconst {\n\t\tgetBlockAttributes,\n\t\tgetBlockName,\n\t\tgetClientIdsWithDescendants,\n\t\t__experimentalGetGlobalBlocksByName: getGlobalBlocksByName,\n\t} = select( blockEditorStore );\n\n\t// FIXME: @wordpress/block-library should not depend on @wordpress/editor.\n\t// Blocks can be loaded into a *non-post* block editor, so to avoid\n\t// declaring @wordpress/editor as a dependency, we must access its\n\t// store by string. When the store is not available, editorSelectors\n\t// will be null, and the block's saved markup will lack permalinks.\n\t// eslint-disable-next-line @wordpress/data-no-store-string-literals\n\tconst permalink = select( 'core/editor' ).getPermalink() ?? null;\n\n\tconst isPaginated = getGlobalBlocksByName( 'core/nextpage' ).length !== 0;\n\tconst { onlyIncludeCurrentPage } = getBlockAttributes( clientId ) ?? {};\n\n\t// Get the client ids of all blocks in the editor.\n\tconst allBlockClientIds = getClientIdsWithDescendants();\n\n\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\tlet tocPage = 1;\n\n\tif ( isPaginated && onlyIncludeCurrentPage ) {\n\t\t// We can't use getBlockIndex because it only returns the index\n\t\t// relative to sibling blocks.\n\t\tconst tocIndex = allBlockClientIds.indexOf( clientId );\n\n\t\tfor ( const [\n\t\t\tblockIndex,\n\t\t\tblockClientId,\n\t\t] of allBlockClientIds.entries() ) {\n\t\t\t// If we've reached blocks after the Table of Contents, we've\n\t\t\t// finished calculating which page the block is on.\n\t\t\tif ( blockIndex >= tocIndex ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif ( getBlockName( blockClientId ) === 'core/nextpage' ) {\n\t\t\t\ttocPage++;\n\t\t\t}\n\t\t}\n\t}\n\n\tconst latestHeadings = [];\n\n\t/** The page (of a paginated post) a heading will be part of. */\n\tlet headingPage = 1;\n\tlet headingPageLink = null;\n\n\t// If the core/editor store is available, we can add permalinks to the\n\t// generated table of contents.\n\tif ( typeof permalink === 'string' ) {\n\t\theadingPageLink = isPaginated\n\t\t\t? addQueryArgs( permalink, { page: headingPage } )\n\t\t\t: permalink;\n\t}\n\n\tfor ( const blockClientId of allBlockClientIds ) {\n\t\tconst blockName = getBlockName( blockClientId );\n\t\tif ( blockName === 'core/nextpage' ) {\n\t\t\theadingPage++;\n\n\t\t\t// If we're only including headings from the current page (of\n\t\t\t// a paginated post), then exit the loop if we've reached the\n\t\t\t// pages after the one with the Table of Contents block.\n\t\t\tif ( onlyIncludeCurrentPage && headingPage > tocPage ) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif ( typeof permalink === 'string' ) {\n\t\t\t\theadingPageLink = addQueryArgs(\n\t\t\t\t\tremoveQueryArgs( permalink, [ 'page' ] ),\n\t\t\t\t\t{ page: headingPage }\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\t// If we're including all headings or we've reached headings on\n\t\t// the same page as the Table of Contents block, add them to the\n\t\t// list.\n\t\telse if ( ! onlyIncludeCurrentPage || headingPage === tocPage ) {\n\t\t\tif ( blockName === 'core/heading' ) {\n\t\t\t\tconst headingAttributes = getBlockAttributes( blockClientId );\n\n\t\t\t\tconst canBeLinked =\n\t\t\t\t\ttypeof headingPageLink === 'string' &&\n\t\t\t\t\ttypeof headingAttributes.anchor === 'string' &&\n\t\t\t\t\theadingAttributes.anchor !== '';\n\n\t\t\t\tlatestHeadings.push( {\n\t\t\t\t\t// Convert line breaks to spaces, and get rid of HTML tags in the headings.\n\t\t\t\t\tcontent: stripHTML(\n\t\t\t\t\t\theadingAttributes.content.replace(\n\t\t\t\t\t\t\t/(<br *\\/?>)+/g,\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\tlevel: headingAttributes.level,\n\t\t\t\t\tlink: canBeLinked\n\t\t\t\t\t\t? `${ headingPageLink }#${ headingAttributes.anchor }`\n\t\t\t\t\t\t: null,\n\t\t\t\t} );\n\t\t\t}\n\t\t}\n\t}\n\n\treturn latestHeadings;\n}\n\nfunction observeCallback( select, dispatch, clientId ) {\n\tconst { getBlockAttributes } = select( blockEditorStore );\n\tconst { updateBlockAttributes, __unstableMarkNextChangeAsNotPersistent } =\n\t\tdispatch( blockEditorStore );\n\n\t/**\n\t * If the block no longer exists in the store, skip the update.\n\t * The \"undo\" action recreates the block and provides a new `clientId`.\n\t * The hook still might be observing the changes while the old block unmounts.\n\t */\n\tconst attributes = getBlockAttributes( clientId );\n\tif ( attributes === null ) {\n\t\treturn;\n\t}\n\n\tconst headings = getLatestHeadings( select, clientId );\n\tif ( ! fastDeepEqual( headings, attributes.headings ) ) {\n\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\tupdateBlockAttributes( clientId, { headings } );\n\t}\n}\n\nexport function useObserveHeadings( clientId ) {\n\tconst registry = useRegistry();\n\tuseEffect( () => {\n\t\t// Todo: Limit subscription to block editor store when data no longer depends on `getPermalink`.\n\t\t// See: https://github.com/WordPress/gutenberg/pull/45513\n\t\treturn registry.subscribe( () =>\n\t\t\tobserveCallback( registry.select, registry.dispatch, clientId )\n\t\t);\n\t}, [ registry, clientId ] );\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,GAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,IAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,IAAA,GAAAJ,OAAA;AACA,IAAAK,YAAA,GAAAL,OAAA;AAZA;AACA;AACA;;AAGA;AACA;AACA;;AAOA,SAASM,iBAAiBA,CAAEC,MAAM,EAAEC,QAAQ,EAAG;EAAA,IAAAC,oBAAA,EAAAC,mBAAA;EAC9C,MAAM;IACLC,kBAAkB;IAClBC,YAAY;IACZC,2BAA2B;IAC3BC,mCAAmC,EAAEC;EACtC,CAAC,GAAGR,MAAM,CAAES,kBAAiB,CAAC;;EAE9B;EACA;EACA;EACA;EACA;EACA;EACA,MAAMC,SAAS,IAAAR,oBAAA,GAAGF,MAAM,CAAE,aAAc,CAAC,CAACW,YAAY,CAAC,CAAC,cAAAT,oBAAA,cAAAA,oBAAA,GAAI,IAAI;EAEhE,MAAMU,WAAW,GAAGJ,qBAAqB,CAAE,eAAgB,CAAC,CAACK,MAAM,KAAK,CAAC;EACzE,MAAM;IAAEC;EAAuB,CAAC,IAAAX,mBAAA,GAAGC,kBAAkB,CAAEH,QAAS,CAAC,cAAAE,mBAAA,cAAAA,mBAAA,GAAI,CAAC,CAAC;;EAEvE;EACA,MAAMY,iBAAiB,GAAGT,2BAA2B,CAAC,CAAC;;EAEvD;EACA,IAAIU,OAAO,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,IAAAC,kBAAS,EAAE,MAAM;IAChB;IACA;IACA,OAAOF,QAAQ,CAACG,SAAS,CAAE,MAC1BX,eAAe,CAAEQ,QAAQ,CAAC9C,MAAM,EAAE8C,QAAQ,CAACP,QAAQ,EAAEtC,QAAS,CAC/D,CAAC;EACF,CAAC,EAAE,CAAE6C,QAAQ,EAAE7C,QAAQ,CAAG,CAAC;AAC5B"}
@@ -27,7 +27,8 @@ const metadata = {
27
27
  type: "array",
28
28
  items: {
29
29
  type: "object"
30
- }
30
+ },
31
+ "default": []
31
32
  },
32
33
  onlyIncludeCurrentPage: {
33
34
  type: "boolean",
@@ -1 +1 @@
1
- {"version":3,"names":["_initBlock","_interopRequireDefault","require","_edit","_icon","_save","metadata","$schema","apiVersion","__experimental","name","title","category","description","keywords","textdomain","attributes","headings","type","items","onlyIncludeCurrentPage","supports","html","color","text","background","gradients","link","spacing","margin","padding","typography","fontSize","lineHeight","__experimentalFontFamily","__experimentalFontWeight","__experimentalFontStyle","__experimentalTextTransform","__experimentalTextDecoration","__experimentalLetterSpacing","__experimentalDefaultControls","example","exports","settings","icon","edit","save","init","initBlock"],"sources":["@wordpress/block-library/src/table-of-contents/index.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\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\nexport const init = () => initBlock( { name, metadata, settings } );\n"],"mappings":";;;;;;;AAGA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,KAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,KAAA,GAAAJ,sBAAA,CAAAC,OAAA;AAPA;AACA;AACA;AAFA,MAAAI,QAAA;EAAAC,OAAA;EAAAC,UAAA;EAAAC,cAAA;EAAAC,IAAA;EAAAC,KAAA;EAAAC,QAAA;EAAAC,WAAA;EAAAC,QAAA;EAAAC,UAAA;EAAAC,UAAA;IAAAC,QAAA;MAAAC,IAAA;MAAAC,KAAA;QAAAD,IAAA;MAAA;IAAA;IAAAE,sBAAA;MAAAF,IAAA;MAAA;IAAA;EAAA;EAAAG,QAAA;IAAAC,IAAA;IAAAC,KAAA;MAAAC,IAAA;MAAAC,UAAA;MAAAC,SAAA;MAAAC,IAAA;IAAA;IAAAC,OAAA;MAAAC,MAAA;MAAAC,OAAA;IAAA;IAAAC,UAAA;MAAAC,QAAA;MAAAC,UAAA;MAAAC,wBAAA;MAAAC,wBAAA;MAAAC,uBAAA;MAAAC,2BAAA;MAAAC,4BAAA;MAAAC,2BAAA;MAAAC,6BAAA;QAAAR,QAAA;MAAA;IAAA;EAAA;EAAAS,OAAA;AAAA;AAAAC,OAAA,CAAApC,QAAA,GAAAA,QAAA;AASA,MAAM;EAAEI;AAAK,CAAC,GAAGJ,QAAQ;AAACoC,OAAA,CAAAhC,IAAA,GAAAA,IAAA;AAInB,MAAMiC,QAAQ,GAAG;EACvBC,IAAI,EAAJA,aAAI;EACJC,IAAI,EAAJA,aAAI;EACJC,IAAI,EAAJA;AACD,CAAC;AAACJ,OAAA,CAAAC,QAAA,GAAAA,QAAA;AAEK,MAAMI,IAAI,GAAGA,CAAA,KAAM,IAAAC,kBAAS,EAAE;EAAEtC,IAAI;EAAEJ,QAAQ;EAAEqC;AAAS,CAAE,CAAC;AAACD,OAAA,CAAAK,IAAA,GAAAA,IAAA"}
1
+ {"version":3,"names":["_initBlock","_interopRequireDefault","require","_edit","_icon","_save","metadata","$schema","apiVersion","__experimental","name","title","category","description","keywords","textdomain","attributes","headings","type","items","onlyIncludeCurrentPage","supports","html","color","text","background","gradients","link","spacing","margin","padding","typography","fontSize","lineHeight","__experimentalFontFamily","__experimentalFontWeight","__experimentalFontStyle","__experimentalTextTransform","__experimentalTextDecoration","__experimentalLetterSpacing","__experimentalDefaultControls","example","exports","settings","icon","edit","save","init","initBlock"],"sources":["@wordpress/block-library/src/table-of-contents/index.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\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\nexport const init = () => initBlock( { name, metadata, settings } );\n"],"mappings":";;;;;;;AAGA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,KAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,KAAA,GAAAJ,sBAAA,CAAAC,OAAA;AAPA;AACA;AACA;AAFA,MAAAI,QAAA;EAAAC,OAAA;EAAAC,UAAA;EAAAC,cAAA;EAAAC,IAAA;EAAAC,KAAA;EAAAC,QAAA;EAAAC,WAAA;EAAAC,QAAA;EAAAC,UAAA;EAAAC,UAAA;IAAAC,QAAA;MAAAC,IAAA;MAAAC,KAAA;QAAAD,IAAA;MAAA;MAAA;IAAA;IAAAE,sBAAA;MAAAF,IAAA;MAAA;IAAA;EAAA;EAAAG,QAAA;IAAAC,IAAA;IAAAC,KAAA;MAAAC,IAAA;MAAAC,UAAA;MAAAC,SAAA;MAAAC,IAAA;IAAA;IAAAC,OAAA;MAAAC,MAAA;MAAAC,OAAA;IAAA;IAAAC,UAAA;MAAAC,QAAA;MAAAC,UAAA;MAAAC,wBAAA;MAAAC,wBAAA;MAAAC,uBAAA;MAAAC,2BAAA;MAAAC,4BAAA;MAAAC,2BAAA;MAAAC,6BAAA;QAAAR,QAAA;MAAA;IAAA;EAAA;EAAAS,OAAA;AAAA;AAAAC,OAAA,CAAApC,QAAA,GAAAA,QAAA;AASA,MAAM;EAAEI;AAAK,CAAC,GAAGJ,QAAQ;AAACoC,OAAA,CAAAhC,IAAA,GAAAA,IAAA;AAInB,MAAMiC,QAAQ,GAAG;EACvBC,IAAI,EAAJA,aAAI;EACJC,IAAI,EAAJA,aAAI;EACJC,IAAI,EAAJA;AACD,CAAC;AAACJ,OAAA,CAAAC,QAAA,GAAAA,QAAA;AAEK,MAAMI,IAAI,GAAGA,CAAA,KAAM,IAAAC,kBAAS,EAAE;EAAEtC,IAAI;EAAEJ,QAAQ;EAAEqC;AAAS,CAAE,CAAC;AAACD,OAAA,CAAAK,IAAA,GAAAA,IAAA"}
@@ -9,6 +9,7 @@ var _element = require("@wordpress/element");
9
9
  var _classnames = _interopRequireDefault(require("classnames"));
10
10
  var _i18n = require("@wordpress/i18n");
11
11
  var _blockEditor = require("@wordpress/block-editor");
12
+ var _blocks = require("@wordpress/blocks");
12
13
  /**
13
14
  * External dependencies
14
15
  */
@@ -22,6 +23,7 @@ function VerseEdit({
22
23
  setAttributes,
23
24
  mergeBlocks,
24
25
  onRemove,
26
+ insertBlocksAfter,
25
27
  style
26
28
  }) {
27
29
  const {
@@ -57,7 +59,8 @@ function VerseEdit({
57
59
  onMerge: mergeBlocks,
58
60
  textAlign: textAlign,
59
61
  ...blockProps,
60
- __unstablePastePlainText: true
62
+ __unstablePastePlainText: true,
63
+ __unstableOnSplitAtDoubleLineEnd: () => insertBlocksAfter((0, _blocks.createBlock)((0, _blocks.getDefaultBlockName)()))
61
64
  }));
62
65
  }
63
66
  //# sourceMappingURL=edit.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_classnames","_interopRequireDefault","require","_i18n","_blockEditor","VerseEdit","attributes","setAttributes","mergeBlocks","onRemove","style","textAlign","content","blockProps","useBlockProps","className","classnames","_element","createElement","Fragment","BlockControls","AlignmentToolbar","value","onChange","nextAlign","RichText","tagName","identifier","preserveWhiteSpace","nextContent","__","placeholder","onMerge","__unstablePastePlainText"],"sources":["@wordpress/block-library/src/verse/edit.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\tRichText,\n\tBlockControls,\n\tAlignmentToolbar,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\n\nexport default function VerseEdit( {\n\tattributes,\n\tsetAttributes,\n\tmergeBlocks,\n\tonRemove,\n\tstyle,\n} ) {\n\tconst { textAlign, content } = attributes;\n\tconst blockProps = useBlockProps( {\n\t\tclassName: classnames( {\n\t\t\t[ `has-text-align-${ textAlign }` ]: textAlign,\n\t\t} ),\n\t\tstyle,\n\t} );\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls>\n\t\t\t\t<AlignmentToolbar\n\t\t\t\t\tvalue={ textAlign }\n\t\t\t\t\tonChange={ ( nextAlign ) => {\n\t\t\t\t\t\tsetAttributes( { textAlign: nextAlign } );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t</BlockControls>\n\t\t\t<RichText\n\t\t\t\ttagName=\"pre\"\n\t\t\t\tidentifier=\"content\"\n\t\t\t\tpreserveWhiteSpace\n\t\t\t\tvalue={ content }\n\t\t\t\tonChange={ ( nextContent ) => {\n\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\tcontent: nextContent,\n\t\t\t\t\t} );\n\t\t\t\t} }\n\t\t\t\taria-label={ __( 'Verse text' ) }\n\t\t\t\tplaceholder={ __( 'Write verse…' ) }\n\t\t\t\tonRemove={ onRemove }\n\t\t\t\tonMerge={ mergeBlocks }\n\t\t\t\ttextAlign={ textAlign }\n\t\t\t\t{ ...blockProps }\n\t\t\t\t__unstablePastePlainText\n\t\t\t/>\n\t\t</>\n\t);\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AATA;AACA;AACA;;AAGA;AACA;AACA;;AASe,SAASG,SAASA,CAAE;EAClCC,UAAU;EACVC,aAAa;EACbC,WAAW;EACXC,QAAQ;EACRC;AACD,CAAC,EAAG;EACH,MAAM;IAAEC,SAAS;IAAEC;EAAQ,CAAC,GAAGN,UAAU;EACzC,MAAMO,UAAU,GAAG,IAAAC,0BAAa,EAAE;IACjCC,SAAS,EAAE,IAAAC,mBAAU,EAAE;MACtB,CAAG,kBAAkBL,SAAW,EAAC,GAAIA;IACtC,CAAE,CAAC;IACHD;EACD,CAAE,CAAC;EAEH,OACC,IAAAO,QAAA,CAAAC,aAAA,EAAAD,QAAA,CAAAE,QAAA,QACC,IAAAF,QAAA,CAAAC,aAAA,EAACd,YAAA,CAAAgB,aAAa,QACb,IAAAH,QAAA,CAAAC,aAAA,EAACd,YAAA,CAAAiB,gBAAgB;IAChBC,KAAK,EAAGX,SAAW;IACnBY,QAAQ,EAAKC,SAAS,IAAM;MAC3BjB,aAAa,CAAE;QAAEI,SAAS,EAAEa;MAAU,CAAE,CAAC;IAC1C;EAAG,CACH,CACa,CAAC,EAChB,IAAAP,QAAA,CAAAC,aAAA,EAACd,YAAA,CAAAqB,QAAQ;IACRC,OAAO,EAAC,KAAK;IACbC,UAAU,EAAC,SAAS;IACpBC,kBAAkB;IAClBN,KAAK,EAAGV,OAAS;IACjBW,QAAQ,EAAKM,WAAW,IAAM;MAC7BtB,aAAa,CAAE;QACdK,OAAO,EAAEiB;MACV,CAAE,CAAC;IACJ,CAAG;IACH,cAAa,IAAAC,QAAE,EAAE,YAAa,CAAG;IACjCC,WAAW,EAAG,IAAAD,QAAE,EAAE,cAAe,CAAG;IACpCrB,QAAQ,EAAGA,QAAU;IACrBuB,OAAO,EAAGxB,WAAa;IACvBG,SAAS,EAAGA,SAAW;IAAA,GAClBE,UAAU;IACfoB,wBAAwB;EAAA,CACxB,CACA,CAAC;AAEL"}
1
+ {"version":3,"names":["_classnames","_interopRequireDefault","require","_i18n","_blockEditor","_blocks","VerseEdit","attributes","setAttributes","mergeBlocks","onRemove","insertBlocksAfter","style","textAlign","content","blockProps","useBlockProps","className","classnames","_element","createElement","Fragment","BlockControls","AlignmentToolbar","value","onChange","nextAlign","RichText","tagName","identifier","preserveWhiteSpace","nextContent","__","placeholder","onMerge","__unstablePastePlainText","__unstableOnSplitAtDoubleLineEnd","createBlock","getDefaultBlockName"],"sources":["@wordpress/block-library/src/verse/edit.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\tRichText,\n\tBlockControls,\n\tAlignmentToolbar,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport { createBlock, getDefaultBlockName } from '@wordpress/blocks';\n\nexport default function VerseEdit( {\n\tattributes,\n\tsetAttributes,\n\tmergeBlocks,\n\tonRemove,\n\tinsertBlocksAfter,\n\tstyle,\n} ) {\n\tconst { textAlign, content } = attributes;\n\tconst blockProps = useBlockProps( {\n\t\tclassName: classnames( {\n\t\t\t[ `has-text-align-${ textAlign }` ]: textAlign,\n\t\t} ),\n\t\tstyle,\n\t} );\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls>\n\t\t\t\t<AlignmentToolbar\n\t\t\t\t\tvalue={ textAlign }\n\t\t\t\t\tonChange={ ( nextAlign ) => {\n\t\t\t\t\t\tsetAttributes( { textAlign: nextAlign } );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t</BlockControls>\n\t\t\t<RichText\n\t\t\t\ttagName=\"pre\"\n\t\t\t\tidentifier=\"content\"\n\t\t\t\tpreserveWhiteSpace\n\t\t\t\tvalue={ content }\n\t\t\t\tonChange={ ( nextContent ) => {\n\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\tcontent: nextContent,\n\t\t\t\t\t} );\n\t\t\t\t} }\n\t\t\t\taria-label={ __( 'Verse text' ) }\n\t\t\t\tplaceholder={ __( 'Write verse…' ) }\n\t\t\t\tonRemove={ onRemove }\n\t\t\t\tonMerge={ mergeBlocks }\n\t\t\t\ttextAlign={ textAlign }\n\t\t\t\t{ ...blockProps }\n\t\t\t\t__unstablePastePlainText\n\t\t\t\t__un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AC;IACJ,CAAG;IACH,cAAa,IAAAC,QAAE,EAAE,YAAa,CAAG;IACjCC,WAAW,EAAG,IAAAD,QAAE,EAAE,cAAe,CAAG;IACpCtB,QAAQ,EAAGA,QAAU;IACrBwB,OAAO,EAAGzB,WAAa;IACvBI,SAAS,EAAGA,SAAW;IAAA,GAClBE,UAAU;IACfoB,wBAAwB;IACxBC,gCAAgC,EAAGA,CAAA,KAClCzB,iBAAiB,CAAE,IAAA0B,mBAAW,EAAE,IAAAC,2BAAmB,EAAC,CAAE,CAAE;EACxD,CACD,CACA,CAAC;AAEL"}
@@ -102,7 +102,7 @@ const settings = {
102
102
  deprecated: _deprecated.default,
103
103
  merge(attributes, attributesToMerge) {
104
104
  return {
105
- content: attributes.content + attributesToMerge.content
105
+ content: attributes.content + '\n\n' + attributesToMerge.content
106
106
  };
107
107
  },
108
108
  edit: _edit.default,