@wordpress/block-library 7.1.1 → 7.2.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 (304) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/build/avatar/edit.js +205 -0
  3. package/build/avatar/edit.js.map +1 -0
  4. package/build/avatar/hooks.js +111 -0
  5. package/build/avatar/hooks.js.map +1 -0
  6. package/build/avatar/index.js +83 -0
  7. package/build/avatar/index.js.map +1 -0
  8. package/build/avatar/user-control.js +63 -0
  9. package/build/avatar/user-control.js.map +1 -0
  10. package/build/column/index.js +2 -1
  11. package/build/column/index.js.map +1 -1
  12. package/build/comment-author-avatar/index.js +1 -0
  13. package/build/comment-author-avatar/index.js.map +1 -1
  14. package/build/comment-date/edit.js +10 -25
  15. package/build/comment-date/edit.js.map +1 -1
  16. package/build/comment-template/edit.js +79 -52
  17. package/build/comment-template/edit.js.map +1 -1
  18. package/build/cover/edit.js +23 -33
  19. package/build/cover/edit.js.map +1 -1
  20. package/build/embed/variations.js +2 -2
  21. package/build/embed/variations.js.map +1 -1
  22. package/build/gallery/edit.js +18 -5
  23. package/build/gallery/edit.js.map +1 -1
  24. package/build/gallery/gallery.js +1 -1
  25. package/build/gallery/gallery.js.map +1 -1
  26. package/build/gallery/gap-styles.js +29 -0
  27. package/build/gallery/gap-styles.js.map +1 -0
  28. package/build/gallery/index.js +17 -1
  29. package/build/gallery/index.js.map +1 -1
  30. package/build/group/index.js +3 -1
  31. package/build/group/index.js.map +1 -1
  32. package/build/group/variations.js +1 -2
  33. package/build/group/variations.js.map +1 -1
  34. package/build/image/image.js +3 -1
  35. package/build/image/image.js.map +1 -1
  36. package/build/index.js +8 -2
  37. package/build/index.js.map +1 -1
  38. package/build/list/index.js +5 -7
  39. package/build/list/index.js.map +1 -1
  40. package/build/list/v2/edit.js +85 -0
  41. package/build/list/v2/edit.js.map +1 -0
  42. package/build/list/v2/index.js +33 -0
  43. package/build/list/v2/index.js.map +1 -0
  44. package/build/list/v2/save.js +34 -0
  45. package/build/list/v2/save.js.map +1 -0
  46. package/build/list/v2/transforms.js +121 -0
  47. package/build/list/v2/transforms.js.map +1 -0
  48. package/build/list-item/edit.js +47 -0
  49. package/build/list-item/edit.js.map +1 -0
  50. package/build/list-item/index.js +67 -0
  51. package/build/list-item/index.js.map +1 -0
  52. package/build/list-item/save.js +23 -0
  53. package/build/list-item/save.js.map +1 -0
  54. package/build/media-text/edit.js +3 -1
  55. package/build/media-text/edit.js.map +1 -1
  56. package/build/navigation/use-navigation-entities.js +26 -54
  57. package/build/navigation/use-navigation-entities.js.map +1 -1
  58. package/build/navigation-link/edit.js +88 -34
  59. package/build/navigation-link/edit.js.map +1 -1
  60. package/build/post-date/edit.js +31 -37
  61. package/build/post-date/edit.js.map +1 -1
  62. package/build/post-featured-image/edit.js +2 -1
  63. package/build/post-featured-image/edit.js.map +1 -1
  64. package/build/pullquote/edit.js +5 -3
  65. package/build/pullquote/edit.js.map +1 -1
  66. package/build/query/variations.js +4 -4
  67. package/build/query/variations.js.map +1 -1
  68. package/build/query-no-results/edit.js +28 -0
  69. package/build/query-no-results/edit.js.map +1 -0
  70. package/build/query-no-results/index.js +54 -0
  71. package/build/query-no-results/index.js.map +1 -0
  72. package/build/query-no-results/save.js +18 -0
  73. package/build/query-no-results/save.js.map +1 -0
  74. package/build/search/edit.js +2 -3
  75. package/build/search/edit.js.map +1 -1
  76. package/build/separator/deprecated.js +83 -0
  77. package/build/separator/deprecated.js.map +1 -0
  78. package/build/separator/edit.js +31 -23
  79. package/build/separator/edit.js.map +1 -1
  80. package/build/separator/index.js +17 -7
  81. package/build/separator/index.js.map +1 -1
  82. package/build/separator/save.js +18 -13
  83. package/build/separator/save.js.map +1 -1
  84. package/build/separator/use-deprecated-opacity.js +39 -0
  85. package/build/separator/use-deprecated-opacity.js.map +1 -0
  86. package/build/social-links/edit.js +14 -3
  87. package/build/social-links/edit.js.map +1 -1
  88. package/build/social-links/index.js +1 -1
  89. package/build/spacer/controls.js +6 -16
  90. package/build/spacer/controls.js.map +1 -1
  91. package/build/spacer/controls.native.js +3 -1
  92. package/build/spacer/controls.native.js.map +1 -1
  93. package/build/spacer/edit.js +4 -5
  94. package/build/spacer/edit.js.map +1 -1
  95. package/build/table/deprecated.js +1 -1
  96. package/build/table/deprecated.js.map +1 -1
  97. package/build/tag-cloud/edit.js +58 -2
  98. package/build/tag-cloud/edit.js.map +1 -1
  99. package/build/tag-cloud/index.js +8 -0
  100. package/build/tag-cloud/index.js.map +1 -1
  101. package/build-module/avatar/edit.js +190 -0
  102. package/build-module/avatar/edit.js.map +1 -0
  103. package/build-module/avatar/hooks.js +99 -0
  104. package/build-module/avatar/hooks.js.map +1 -0
  105. package/build-module/avatar/index.js +70 -0
  106. package/build-module/avatar/index.js.map +1 -0
  107. package/build-module/avatar/user-control.js +52 -0
  108. package/build-module/avatar/user-control.js.map +1 -0
  109. package/build-module/column/index.js +2 -1
  110. package/build-module/column/index.js.map +1 -1
  111. package/build-module/comment-author-avatar/index.js +1 -0
  112. package/build-module/comment-author-avatar/index.js.map +1 -1
  113. package/build-module/comment-date/edit.js +13 -30
  114. package/build-module/comment-date/edit.js.map +1 -1
  115. package/build-module/comment-template/edit.js +79 -52
  116. package/build-module/comment-template/edit.js.map +1 -1
  117. package/build-module/cover/edit.js +23 -34
  118. package/build-module/cover/edit.js.map +1 -1
  119. package/build-module/embed/variations.js +2 -2
  120. package/build-module/embed/variations.js.map +1 -1
  121. package/build-module/gallery/edit.js +17 -5
  122. package/build-module/gallery/edit.js.map +1 -1
  123. package/build-module/gallery/gallery.js +1 -1
  124. package/build-module/gallery/gallery.js.map +1 -1
  125. package/build-module/gallery/gap-styles.js +22 -0
  126. package/build-module/gallery/gap-styles.js.map +1 -0
  127. package/build-module/gallery/index.js +17 -1
  128. package/build-module/gallery/index.js.map +1 -1
  129. package/build-module/group/index.js +3 -1
  130. package/build-module/group/index.js.map +1 -1
  131. package/build-module/group/variations.js +1 -2
  132. package/build-module/group/variations.js.map +1 -1
  133. package/build-module/image/image.js +3 -1
  134. package/build-module/image/image.js.map +1 -1
  135. package/build-module/index.js +5 -2
  136. package/build-module/index.js.map +1 -1
  137. package/build-module/list/index.js +5 -1
  138. package/build-module/list/index.js.map +1 -1
  139. package/build-module/list/v2/edit.js +69 -0
  140. package/build-module/list/v2/edit.js.map +1 -0
  141. package/build-module/list/v2/index.js +19 -0
  142. package/build-module/list/v2/index.js.map +1 -0
  143. package/build-module/list/v2/save.js +23 -0
  144. package/build-module/list/v2/save.js.map +1 -0
  145. package/build-module/list/v2/transforms.js +111 -0
  146. package/build-module/list/v2/transforms.js.map +1 -0
  147. package/build-module/list-item/edit.js +37 -0
  148. package/build-module/list-item/edit.js.map +1 -0
  149. package/build-module/list-item/index.js +53 -0
  150. package/build-module/list-item/index.js.map +1 -0
  151. package/build-module/list-item/save.js +15 -0
  152. package/build-module/list-item/save.js.map +1 -0
  153. package/build-module/media-text/edit.js +3 -1
  154. package/build-module/media-text/edit.js.map +1 -1
  155. package/build-module/navigation/use-navigation-entities.js +27 -54
  156. package/build-module/navigation/use-navigation-entities.js.map +1 -1
  157. package/build-module/navigation-link/edit.js +88 -33
  158. package/build-module/navigation-link/edit.js.map +1 -1
  159. package/build-module/post-date/edit.js +32 -43
  160. package/build-module/post-date/edit.js.map +1 -1
  161. package/build-module/post-featured-image/edit.js +2 -1
  162. package/build-module/post-featured-image/edit.js.map +1 -1
  163. package/build-module/pullquote/edit.js +6 -3
  164. package/build-module/pullquote/edit.js.map +1 -1
  165. package/build-module/query/variations.js +4 -4
  166. package/build-module/query/variations.js.map +1 -1
  167. package/build-module/query-no-results/edit.js +18 -0
  168. package/build-module/query-no-results/edit.js.map +1 -0
  169. package/build-module/query-no-results/index.js +40 -0
  170. package/build-module/query-no-results/index.js.map +1 -0
  171. package/build-module/query-no-results/save.js +10 -0
  172. package/build-module/query-no-results/save.js.map +1 -0
  173. package/build-module/search/edit.js +2 -3
  174. package/build-module/search/edit.js.map +1 -1
  175. package/build-module/separator/deprecated.js +70 -0
  176. package/build-module/separator/deprecated.js.map +1 -0
  177. package/build-module/separator/edit.js +31 -22
  178. package/build-module/separator/edit.js.map +1 -1
  179. package/build-module/separator/index.js +16 -7
  180. package/build-module/separator/index.js.map +1 -1
  181. package/build-module/separator/save.js +19 -14
  182. package/build-module/separator/save.js.map +1 -1
  183. package/build-module/separator/use-deprecated-opacity.js +30 -0
  184. package/build-module/separator/use-deprecated-opacity.js.map +1 -0
  185. package/build-module/social-links/edit.js +15 -4
  186. package/build-module/social-links/edit.js.map +1 -1
  187. package/build-module/social-links/index.js +1 -1
  188. package/build-module/spacer/controls.js +8 -19
  189. package/build-module/spacer/controls.js.map +1 -1
  190. package/build-module/spacer/controls.native.js +2 -1
  191. package/build-module/spacer/controls.native.js.map +1 -1
  192. package/build-module/spacer/edit.js +3 -3
  193. package/build-module/spacer/edit.js.map +1 -1
  194. package/build-module/table/deprecated.js +1 -1
  195. package/build-module/table/deprecated.js.map +1 -1
  196. package/build-module/tag-cloud/edit.js +60 -4
  197. package/build-module/tag-cloud/edit.js.map +1 -1
  198. package/build-module/tag-cloud/index.js +8 -0
  199. package/build-module/tag-cloud/index.js.map +1 -1
  200. package/build-style/avatar/editor-rtl.css +79 -0
  201. package/build-style/avatar/editor.css +79 -0
  202. package/build-style/editor-rtl.css +23 -2
  203. package/build-style/editor.css +23 -2
  204. package/build-style/gallery/editor-rtl.css +0 -1
  205. package/build-style/gallery/editor.css +0 -1
  206. package/build-style/gallery/style-rtl.css +102 -169
  207. package/build-style/gallery/style.css +102 -169
  208. package/build-style/image/style-rtl.css +2 -0
  209. package/build-style/image/style.css +2 -0
  210. package/build-style/navigation-link/editor-rtl.css +13 -0
  211. package/build-style/navigation-link/editor.css +13 -0
  212. package/build-style/pullquote/style-rtl.css +0 -4
  213. package/build-style/pullquote/style.css +0 -4
  214. package/build-style/separator/editor-rtl.css +3 -0
  215. package/build-style/separator/editor.css +3 -0
  216. package/build-style/separator/theme-rtl.css +7 -1
  217. package/build-style/separator/theme.css +7 -1
  218. package/build-style/site-logo/editor-rtl.css +3 -1
  219. package/build-style/site-logo/editor.css +3 -1
  220. package/build-style/style-rtl.css +104 -173
  221. package/build-style/style.css +104 -173
  222. package/build-style/theme-rtl.css +7 -1
  223. package/build-style/theme.css +7 -1
  224. package/package.json +28 -28
  225. package/src/avatar/block.json +53 -0
  226. package/src/avatar/edit.js +222 -0
  227. package/src/avatar/editor.scss +3 -0
  228. package/src/avatar/hooks.js +96 -0
  229. package/src/avatar/index.js +18 -0
  230. package/src/avatar/index.php +146 -0
  231. package/src/avatar/user-control.js +56 -0
  232. package/src/column/block.json +2 -1
  233. package/src/comment-author-avatar/block.json +1 -0
  234. package/src/comment-date/edit.js +20 -30
  235. package/src/comment-template/edit.js +65 -44
  236. package/src/cover/edit.js +26 -31
  237. package/src/editor.scss +1 -0
  238. package/src/embed/variations.js +2 -2
  239. package/src/gallery/block.json +17 -1
  240. package/src/gallery/deprecated.scss +2 -2
  241. package/src/gallery/edit.js +15 -8
  242. package/src/gallery/editor.scss +0 -1
  243. package/src/gallery/gallery.js +8 -7
  244. package/src/gallery/gap-styles.js +21 -0
  245. package/src/gallery/index.php +42 -1
  246. package/src/gallery/style.scss +11 -44
  247. package/src/group/block.json +3 -1
  248. package/src/group/variations.js +1 -1
  249. package/src/image/image.js +4 -1
  250. package/src/image/style.scss +3 -0
  251. package/src/index.js +6 -1
  252. package/src/list/index.js +6 -1
  253. package/src/list/v2/edit.js +77 -0
  254. package/src/list/v2/index.js +20 -0
  255. package/src/list/v2/save.js +18 -0
  256. package/src/list/v2/transforms.js +116 -0
  257. package/src/list-item/block.json +26 -0
  258. package/src/list-item/edit.js +47 -0
  259. package/src/list-item/index.js +27 -0
  260. package/src/list-item/save.js +13 -0
  261. package/src/media-text/edit.js +1 -1
  262. package/src/navigation/index.php +22 -2
  263. package/src/navigation/use-navigation-entities.js +37 -73
  264. package/src/navigation-link/edit.js +145 -61
  265. package/src/navigation-link/editor.scss +11 -0
  266. package/src/post-date/edit.js +63 -52
  267. package/src/post-date/index.php +1 -1
  268. package/src/post-date/test/edit.js +17 -0
  269. package/src/post-featured-image/edit.js +9 -1
  270. package/src/post-featured-image/index.php +2 -1
  271. package/src/pullquote/edit.js +4 -3
  272. package/src/pullquote/style.scss +0 -5
  273. package/src/query/variations.js +4 -0
  274. package/src/query-no-results/block.json +20 -0
  275. package/src/query-no-results/edit.js +28 -0
  276. package/src/query-no-results/index.js +20 -0
  277. package/src/query-no-results/index.php +59 -0
  278. package/src/query-no-results/save.js +8 -0
  279. package/src/search/edit.js +1 -2
  280. package/src/separator/block.json +13 -6
  281. package/src/separator/deprecated.js +57 -0
  282. package/src/separator/deprecated.scss +6 -0
  283. package/src/separator/edit.js +36 -14
  284. package/src/separator/editor.scss +6 -0
  285. package/src/separator/index.js +2 -0
  286. package/src/separator/save.js +22 -14
  287. package/src/separator/test/edit.js +113 -0
  288. package/src/separator/theme.scss +7 -1
  289. package/src/separator/use-deprecated-opacity.js +41 -0
  290. package/src/site-logo/editor.scss +3 -1
  291. package/src/social-links/block.json +1 -1
  292. package/src/social-links/edit.js +15 -5
  293. package/src/spacer/controls.js +12 -18
  294. package/src/spacer/controls.native.js +2 -1
  295. package/src/spacer/edit.js +3 -6
  296. package/src/table/deprecated.js +5 -1
  297. package/src/tag-cloud/block.json +8 -0
  298. package/src/tag-cloud/edit.js +82 -2
  299. package/src/tag-cloud/index.php +6 -0
  300. package/build/separator/separator-settings.js +0 -36
  301. package/build/separator/separator-settings.js.map +0 -1
  302. package/build-module/separator/separator-settings.js +0 -27
  303. package/build-module/separator/separator-settings.js.map +0 -1
  304. package/src/separator/separator-settings.js +0 -24
@@ -30,10 +30,14 @@ var _hooks = require("./hooks");
30
30
  /**
31
31
  * Internal dependencies
32
32
  */
33
- const TEMPLATE = [['core/comment-author-avatar'], ['core/comment-author-name'], ['core/comment-date'], ['core/comment-content'], ['core/comment-reply-link'], ['core/comment-edit-link']];
33
+ const TEMPLATE = [['core/avatar'], ['core/comment-author-name'], ['core/comment-date'], ['core/comment-content'], ['core/comment-reply-link'], ['core/comment-edit-link']];
34
34
  /**
35
35
  * Function that returns a comment structure that will be rendered with default placehoders.
36
36
  *
37
+ * Each comment has a `commentId` property that is always a negative number in
38
+ * case of the placeholders. This is to ensure that the comment does not
39
+ * conflict with the actual (real) comments.
40
+ *
37
41
  * @param {Object} settings Discussion Settings.
38
42
  * @param {number} [settings.perPage] - Comments per page setting or block attribute.
39
43
  * @param {boolean} [settings.threadComments] - Enable threaded (nested) comments setting.
@@ -58,15 +62,16 @@ const getCommentsPlaceholder = _ref => {
58
62
 
59
63
  if (!threadComments || defaultCommentsToShow === 1) {
60
64
  // If displaying threaded comments is disabled, we only show one comment
65
+ // A commentId is negative in order to avoid conflicts with the actual comments.
61
66
  return [{
62
- commentId: null,
67
+ commentId: -1,
63
68
  children: []
64
69
  }];
65
70
  } else if (defaultCommentsToShow === 2) {
66
71
  return [{
67
- commentId: null,
72
+ commentId: -1,
68
73
  children: [{
69
- commentId: null,
74
+ commentId: -2,
70
75
  children: []
71
76
  }]
72
77
  }];
@@ -74,11 +79,11 @@ const getCommentsPlaceholder = _ref => {
74
79
 
75
80
 
76
81
  return [{
77
- commentId: null,
82
+ commentId: -1,
78
83
  children: [{
79
- commentId: null,
84
+ commentId: -2,
80
85
  children: [{
81
- commentId: null,
86
+ commentId: -3,
82
87
  children: []
83
88
  }]
84
89
  }]
@@ -87,13 +92,13 @@ const getCommentsPlaceholder = _ref => {
87
92
  /**
88
93
  * Component which renders the inner blocks of the Comment Template.
89
94
  *
90
- * @param {Object} props Component props.
91
- * @param {Array} [props.comment] - A comment object.
92
- * @param {Array} [props.activeComment] - The block that is currently active.
93
- * @param {Array} [props.setActiveComment] - The setter for activeComment.
94
- * @param {Array} [props.firstComment] - First comment in the array.
95
- * @param {Array} [props.blocks] - Array of blocks returned from
96
- * getBlocks() in parent .
95
+ * @param {Object} props Component props.
96
+ * @param {Array} [props.comment] - A comment object.
97
+ * @param {Array} [props.activeCommentId] - The ID of the comment that is currently active.
98
+ * @param {Array} [props.setActiveCommentId] - The setter for activeCommentId.
99
+ * @param {Array} [props.firstCommentId] - ID of the first comment in the array.
100
+ * @param {Array} [props.blocks] - Array of blocks returned from
101
+ * getBlocks() in parent .
97
102
  * @return {WPElement} Inner blocks of the Comment Template
98
103
  */
99
104
 
@@ -103,9 +108,9 @@ function CommentTemplateInnerBlocks(_ref2) {
103
108
 
104
109
  let {
105
110
  comment,
106
- activeComment,
107
- setActiveComment,
108
- firstComment,
111
+ activeCommentId,
112
+ setActiveCommentId,
113
+ firstCommentId,
109
114
  blocks
110
115
  } = _ref2;
111
116
  const {
@@ -114,24 +119,25 @@ function CommentTemplateInnerBlocks(_ref2) {
114
119
  } = (0, _blockEditor.useInnerBlocksProps)({}, {
115
120
  template: TEMPLATE
116
121
  });
117
- return (0, _element.createElement)("li", innerBlocksProps, comment === (activeComment || firstComment) ? children : null, (0, _element.createElement)(MemoizedCommentTemplatePreview, {
122
+ return (0, _element.createElement)("li", innerBlocksProps, comment.commentId === (activeCommentId || firstCommentId) ? children : null, (0, _element.createElement)(MemoizedCommentTemplatePreview, {
118
123
  blocks: blocks,
119
- comment: comment,
120
- setActiveComment: setActiveComment,
121
- isHidden: comment === (activeComment || firstComment)
124
+ commentId: comment.commentId,
125
+ setActiveCommentId: setActiveCommentId,
126
+ isHidden: comment.commentId === (activeCommentId || firstCommentId)
122
127
  }), (comment === null || comment === void 0 ? void 0 : (_comment$children = comment.children) === null || _comment$children === void 0 ? void 0 : _comment$children.length) > 0 ? (0, _element.createElement)(CommentsList, {
123
128
  comments: comment.children,
124
- activeComment: activeComment,
125
- setActiveComment: setActiveComment,
126
- blocks: blocks
129
+ activeCommentId: activeCommentId,
130
+ setActiveCommentId: setActiveCommentId,
131
+ blocks: blocks,
132
+ firstCommentId: firstCommentId
127
133
  }) : null);
128
134
  }
129
135
 
130
136
  const CommentTemplatePreview = _ref3 => {
131
137
  let {
132
138
  blocks,
133
- comment,
134
- setActiveComment,
139
+ commentId,
140
+ setActiveCommentId,
135
141
  isHidden
136
142
  } = _ref3;
137
143
  const blockPreviewProps = (0, _blockEditor.__experimentalUseBlockPreview)({
@@ -139,7 +145,7 @@ const CommentTemplatePreview = _ref3 => {
139
145
  });
140
146
 
141
147
  const handleOnClick = () => {
142
- setActiveComment(comment);
148
+ setActiveCommentId(commentId);
143
149
  }; // We have to hide the preview block if the `comment` props points to
144
150
  // the curently active block!
145
151
  // Or, to put it differently, every preview block is visible unless it is the
@@ -163,13 +169,14 @@ const MemoizedCommentTemplatePreview = (0, _element.memo)(CommentTemplatePreview
163
169
  /**
164
170
  * Component that renders a list of (nested) comments. It is called recursively.
165
171
  *
166
- * @param {Object} props Component props.
167
- * @param {Array} [props.comments] - Array of comment objects.
168
- * @param {Array} [props.blockProps] - Props from parent's `useBlockProps()`.
169
- * @param {Array} [props.activeComment] - The block that is currently active.
170
- * @param {Array} [props.setActiveComment] - The setter for activeComment.
171
- * @param {Array} [props.blocks] - Array of blocks returned from
172
- * getBlocks() in parent .
172
+ * @param {Object} props Component props.
173
+ * @param {Array} [props.comments] - Array of comment objects.
174
+ * @param {Array} [props.blockProps] - Props from parent's `useBlockProps()`.
175
+ * @param {Array} [props.activeCommentId] - The ID of the comment that is currently active.
176
+ * @param {Array} [props.setActiveCommentId] - The setter for activeCommentId.
177
+ * @param {Array} [props.blocks] - Array of blocks returned from getBlocks() in parent.
178
+ * @param {Object} [props.firstCommentId] - The ID of the first comment in the array of
179
+ * comment objects.
173
180
  * @return {WPElement} List of comments.
174
181
  */
175
182
 
@@ -177,23 +184,42 @@ const CommentsList = _ref4 => {
177
184
  let {
178
185
  comments,
179
186
  blockProps,
180
- activeComment,
181
- setActiveComment,
182
- blocks
187
+ activeCommentId,
188
+ setActiveCommentId,
189
+ blocks,
190
+ firstCommentId
183
191
  } = _ref4;
184
- return (0, _element.createElement)("ol", blockProps, comments && comments.map((comment, index) => (0, _element.createElement)(_blockEditor.BlockContextProvider, {
185
- key: comment.commentId || index,
186
- value: comment
187
- }, (0, _element.createElement)(CommentTemplateInnerBlocks, {
188
- comment: comment,
189
- activeComment: activeComment,
190
- setActiveComment: setActiveComment,
191
- blocks: blocks,
192
- firstComment: comments[0]
193
- }))));
192
+ return (0, _element.createElement)("ol", blockProps, comments && comments.map((_ref5, index) => {
193
+ let {
194
+ commentId,
195
+ ...comment
196
+ } = _ref5;
197
+ return (0, _element.createElement)(_blockEditor.BlockContextProvider, {
198
+ key: comment.commentId || index,
199
+ value: {
200
+ // If the commentId is negative it means that this comment is a
201
+ // "placeholder" and that the block is most likely being used in the
202
+ // site editor. In this case, we have to set the commentId to `null`
203
+ // because otherwise the (non-existent) comment with a negative ID
204
+ // would be reqested from the REST API.
205
+ commentId: commentId < 0 ? null : commentId
206
+ }
207
+ }, (0, _element.createElement)(CommentTemplateInnerBlocks, {
208
+ comment: {
209
+ commentId,
210
+ ...comment
211
+ },
212
+ activeCommentId: activeCommentId,
213
+ setActiveCommentId: setActiveCommentId,
214
+ blocks: blocks,
215
+ firstCommentId: firstCommentId
216
+ }));
217
+ }));
194
218
  };
195
219
 
196
- function CommentTemplateEdit(_ref5) {
220
+ function CommentTemplateEdit(_ref6) {
221
+ var _commentTree$;
222
+
197
223
  let {
198
224
  clientId,
199
225
  context: {
@@ -203,9 +229,9 @@ function CommentTemplateEdit(_ref5) {
203
229
  'comments/defaultPage': defaultPage,
204
230
  'comments/inherit': inherit
205
231
  }
206
- } = _ref5;
232
+ } = _ref6;
207
233
  const blockProps = (0, _blockEditor.useBlockProps)();
208
- const [activeComment, setActiveComment] = (0, _element.useState)();
234
+ const [activeCommentId, setActiveCommentId] = (0, _element.useState)();
209
235
  const {
210
236
  commentOrder,
211
237
  threadCommentsDepth,
@@ -263,8 +289,9 @@ function CommentTemplateEdit(_ref5) {
263
289
  comments: commentTree,
264
290
  blockProps: blockProps,
265
291
  blocks: blocks,
266
- activeComment: activeComment,
267
- setActiveComment: setActiveComment
292
+ activeCommentId: activeCommentId,
293
+ setActiveCommentId: setActiveCommentId,
294
+ firstCommentId: (_commentTree$ = commentTree[0]) === null || _commentTree$ === void 0 ? void 0 : _commentTree$.commentId
268
295
  });
269
296
  }
270
297
  //# sourceMappingURL=edit.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-library/src/comment-template/edit.js"],"names":["TEMPLATE","getCommentsPlaceholder","perPage","threadComments","threadCommentsDepth","commentsDepth","Math","min","defaultCommentsToShow","commentId","children","CommentTemplateInnerBlocks","comment","activeComment","setActiveComment","firstComment","blocks","innerBlocksProps","template","length","CommentTemplatePreview","isHidden","blockPreviewProps","handleOnClick","style","display","undefined","MemoizedCommentTemplatePreview","CommentsList","comments","blockProps","map","index","CommentTemplateEdit","clientId","context","postId","order","defaultPage","inherit","commentOrder","select","getSettings","blockEditorStore","__experimentalDiscussionSettings","commentQuery","topLevelComments","getEntityRecords","coreStore","getBlocks","commentTree","reverse"],"mappings":";;;;;;;;;AAGA;;;;AACA;;AACA;;AACA;;AAOA;;AACA;;AAKA;;AAnBA;AACA;AACA;;AAcA;AACA;AACA;AAGA,MAAMA,QAAQ,GAAG,CAChB,CAAE,4BAAF,CADgB,EAEhB,CAAE,0BAAF,CAFgB,EAGhB,CAAE,mBAAF,CAHgB,EAIhB,CAAE,sBAAF,CAJgB,EAKhB,CAAE,yBAAF,CALgB,EAMhB,CAAE,wBAAF,CANgB,CAAjB;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,sBAAsB,GAAG,QAIxB;AAAA,MAJ0B;AAChCC,IAAAA,OADgC;AAEhCC,IAAAA,cAFgC;AAGhCC,IAAAA;AAHgC,GAI1B;AACN;AACA;AACA;AACA,QAAMC,aAAa,GAAGC,IAAI,CAACC,GAAL,CAAUH,mBAAmB,IAAI,CAAjC,EAAoC,CAApC,CAAtB,CAJM,CAMN;;AACA,QAAMI,qBAAqB,GAC1BN,OA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B,EAAGC;AALpB,IADD;AASA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, memo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tBlockContextProvider,\n\tuseBlockProps,\n\tuseInnerBlocksProps,\n\tstore as blockEditorStore,\n\t__experimentalUseBlockPreview as useBlockPreview,\n} from '@wordpress/block-editor';\nimport { Spinner } from '@wordpress/components';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { useCommentQueryArgs, useCommentTree } from './hooks';\n\nconst TEMPLATE = [\n\t[ 'core/comment-author-avatar' ],\n\t[ 'core/comment-author-name' ],\n\t[ 'core/comment-date' ],\n\t[ 'core/comment-content' ],\n\t[ 'core/comment-reply-link' ],\n\t[ 'core/comment-edit-link' ],\n];\n\n/**\n * Function that returns a comment structure that will be rendered with default placehoders.\n *\n * @param {Object} settings Discussion Settings.\n * @param {number} [settings.perPage] - Comments per page setting or block attribute.\n * @param {boolean} [settings.threadComments] - Enable threaded (nested) comments setting.\n * @param {number} [settings.threadCommentsDepth] - Level deep of threaded comments.\n *\n * @typedef {{id: null, children: EmptyComment[]}} EmptyComment\n * @return {EmptyComment[]} \t\tInner blocks of the Comment Template\n */\nconst getCommentsPlaceholder = ( {\n\tperPage,\n\tthreadComments,\n\tthreadCommentsDepth,\n} ) => {\n\t// In case that `threadCommentsDepth` is falsy, we default to a somewhat\n\t// arbitrary value of 3.\n\t// In case that the value is set but larger than 3 we truncate it to 3.\n\tconst commentsDepth = Math.min( threadCommentsDepth || 3, 3 );\n\n\t// We set a limit in order not to overload the editor of empty comments.\n\tconst defaultCommentsToShow =\n\t\tperPage <= commentsDepth ? perPage : commentsDepth;\n\tif ( ! threadComments || defaultCommentsToShow === 1 ) {\n\t\t// If displaying threaded comments is disabled, we only show one comment\n\t\treturn [ { commentId: null, children: [] } ];\n\t} else if ( defaultCommentsToShow === 2 ) {\n\t\treturn [\n\t\t\t{\n\t\t\t\tcommentId: null,\n\t\t\t\tchildren: [ { commentId: null, children: [] } ],\n\t\t\t},\n\t\t];\n\t}\n\n\t// In case that the value is set but larger than 3 we truncate it to 3.\n\treturn [\n\t\t{\n\t\t\tcommentId: null,\n\t\t\tchildren: [\n\t\t\t\t{\n\t\t\t\t\tcommentId: null,\n\t\t\t\t\tchildren: [ { commentId: null, children: [] } ],\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t];\n};\n\n/**\n * Component which renders the inner blocks of the Comment Template.\n *\n * @param {Object} props Component props.\n * @param {Array} [props.comment] - A comment object.\n * @param {Array} [props.activeComment] - The block that is currently active.\n * @param {Array} [props.setActiveComment] - The setter for activeComment.\n * @param {Array} [props.firstComment] - First comment in the array.\n * @param {Array} [props.blocks] - Array of blocks returned from\n * getBlocks() in parent .\n * @return {WPElement} \t\tInner blocks of the Comment Template\n */\nfunction CommentTemplateInnerBlocks( {\n\tcomment,\n\tactiveComment,\n\tsetActiveComment,\n\tfirstComment,\n\tblocks,\n} ) {\n\tconst { children, ...innerBlocksProps } = useInnerBlocksProps(\n\t\t{},\n\t\t{ template: TEMPLATE }\n\t);\n\treturn (\n\t\t<li { ...innerBlocksProps }>\n\t\t\t{ comment === ( activeComment || firstComment ) ? children : null }\n\n\t\t\t{ /* To avoid flicker when switching active block contexts, a preview\n\t\t\tis ALWAYS rendered and the preview for the active block is hidden.\n\t\t\tThis ensures that when switching the active block, the component is not\n\t\t\tmounted again but rather it only toggles the `isHidden` prop.\n\n\t\t\tThe same strategy is used for preventing the flicker in the Post Template\n\t\t\tblock. */ }\n\t\t\t<MemoizedCommentTemplatePreview\n\t\t\t\tblocks={ blocks }\n\t\t\t\tcomment={ comment }\n\t\t\t\tsetActiveComment={ setActiveComment }\n\t\t\t\tisHidden={ comment === ( activeComment || firstComment ) }\n\t\t\t/>\n\n\t\t\t{ comment?.children?.length > 0 ? (\n\t\t\t\t<CommentsList\n\t\t\t\t\tcomments={ comment.children }\n\t\t\t\t\tactiveComment={ activeComment }\n\t\t\t\t\tsetActiveComment={ setActiveComment }\n\t\t\t\t\tblocks={ blocks }\n\t\t\t\t/>\n\t\t\t) : null }\n\t\t</li>\n\t);\n}\n\nconst CommentTemplatePreview = ( {\n\tblocks,\n\tcomment,\n\tsetActiveComment,\n\tisHidden,\n} ) => {\n\tconst blockPreviewProps = useBlockPreview( {\n\t\tblocks,\n\t} );\n\n\tconst handleOnClick = () => {\n\t\tsetActiveComment( comment );\n\t};\n\n\t// We have to hide the preview block if the `comment` props points to\n\t// the curently active block!\n\n\t// Or, to put it differently, every preview block is visible unless it is the\n\t// currently active block - in this case we render its inner blocks.\n\tconst style = {\n\t\tdisplay: isHidden ? 'none' : undefined,\n\t};\n\n\treturn (\n\t\t<div\n\t\t\t{ ...blockPreviewProps }\n\t\t\ttabIndex={ 0 }\n\t\t\trole=\"button\"\n\t\t\tstyle={ style }\n\t\t\t// eslint-disable-next-line jsx-a11y/no-noninteractive-element-to-interactive-role\n\t\t\tonClick={ handleOnClick }\n\t\t\tonKeyPress={ handleOnClick }\n\t\t/>\n\t);\n};\n\nconst MemoizedCommentTemplatePreview = memo( CommentTemplatePreview );\n\n/**\n * Component that renders a list of (nested) comments. It is called recursively.\n *\n * @param {Object} props Component props.\n * @param {Array} [props.comments] - Array of comment objects.\n * @param {Array} [props.blockProps] - Props from parent's `useBlockProps()`.\n * @param {Array} [props.activeComment] - The block that is currently active.\n * @param {Array} [props.setActiveComment] - The setter for activeComment.\n * @param {Array} [props.blocks] - Array of blocks returned from\n * getBlocks() in parent .\n * @return {WPElement} \t\tList of comments.\n */\nconst CommentsList = ( {\n\tcomments,\n\tblockProps,\n\tactiveComment,\n\tsetActiveComment,\n\tblocks,\n} ) => (\n\t<ol { ...blockProps }>\n\t\t{ comments &&\n\t\t\tcomments.map( ( comment, index ) => (\n\t\t\t\t<BlockContextProvider\n\t\t\t\t\tkey={ comment.commentId || index }\n\t\t\t\t\tvalue={ comment }\n\t\t\t\t>\n\t\t\t\t\t<CommentTemplateInnerBlocks\n\t\t\t\t\t\tcomment={ comment }\n\t\t\t\t\t\tactiveComment={ activeComment }\n\t\t\t\t\t\tsetActiveComment={ setActiveComment }\n\t\t\t\t\t\tblocks={ blocks }\n\t\t\t\t\t\tfirstComment={ comments[ 0 ] }\n\t\t\t\t\t/>\n\t\t\t\t</BlockContextProvider>\n\t\t\t) ) }\n\t</ol>\n);\n\nexport default function CommentTemplateEdit( {\n\tclientId,\n\tcontext: {\n\t\tpostId,\n\t\t'comments/perPage': perPage,\n\t\t'comments/order': order,\n\t\t'comments/defaultPage': defaultPage,\n\t\t'comments/inherit': inherit,\n\t},\n} ) {\n\tconst blockProps = useBlockProps();\n\n\tconst [ activeComment, setActiveComment ] = useState();\n\tconst { commentOrder, threadCommentsDepth, threadComments } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getSettings } = select( blockEditorStore );\n\t\t\treturn getSettings().__experimentalDiscussionSettings;\n\t\t}\n\t);\n\n\tconst commentQuery = useCommentQueryArgs( {\n\t\tpostId,\n\t\tperPage,\n\t\tdefaultPage,\n\t\tinherit,\n\t} );\n\n\tconst { topLevelComments, blocks } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecords } = select( coreStore );\n\t\t\tconst { getBlocks } = select( blockEditorStore );\n\n\t\t\treturn {\n\t\t\t\t// Request only top-level comments. Replies are embedded.\n\t\t\t\ttopLevelComments: commentQuery\n\t\t\t\t\t? getEntityRecords( 'root', 'comment', commentQuery )\n\t\t\t\t\t: null,\n\t\t\t\tblocks: getBlocks( clientId ),\n\t\t\t};\n\t\t},\n\t\t[ clientId, commentQuery ]\n\t);\n\n\torder = inherit || ! order ? commentOrder : order;\n\n\t// Generate a tree structure of comment IDs.\n\tlet commentTree = useCommentTree(\n\t\t// Reverse the order of top comments if needed.\n\t\torder === 'desc' && topLevelComments\n\t\t\t? [ ...topLevelComments ].reverse()\n\t\t\t: topLevelComments\n\t);\n\n\tif ( ! topLevelComments ) {\n\t\treturn (\n\t\t\t<p { ...blockProps }>\n\t\t\t\t<Spinner />\n\t\t\t</p>\n\t\t);\n\t}\n\n\tif ( ! postId ) {\n\t\tcommentTree = getCommentsPlaceholder( {\n\t\t\tperPage,\n\t\t\tthreadComments,\n\t\t\tthreadCommentsDepth,\n\t\t} );\n\t}\n\n\tif ( ! commentTree.length ) {\n\t\treturn <p { ...blockProps }> { __( 'No results found.' ) }</p>;\n\t}\n\n\treturn (\n\t\t<CommentsList\n\t\t\tcomments={ commentTree }\n\t\t\tblockProps={ blockProps }\n\t\t\tblocks={ blocks }\n\t\t\tactiveComment={ activeComment }\n\t\t\tsetActiveComment={ setActiveComment }\n\t\t/>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-library/src/comment-template/edit.js"],"names":["TEMPLATE","getCommentsPlaceholder","perPage","threadComments","threadCommentsDepth","commentsDepth","Math","min","defaultCommentsToShow","commentId","children","CommentTemplateInnerBlocks","comment","activeCommentId","setActiveCommentId","firstCommentId","blocks","innerBlocksProps","template","length","CommentTemplatePreview","isHidden","blockPreviewProps","handleOnClick","style","display","undefined","MemoizedCommentTemplatePreview","CommentsList","comments","blockProps","map","index","CommentTemplateEdit","clientId","context","postId","order","defaultPage","inherit","commentOrder","select","getSettings","blockEditorStore","__experimentalDiscussionSettings","commentQuery","topLevelComments","getEntityRecords","coreStore","getBlocks","commentTree","reverse"],"mappings":";;;;;;;;;AAGA;;;;AACA;;AACA;;AACA;;AAOA;;AACA;;AAKA;;AAnBA;AACA;AACA;;AAcA;AACA;AACA;AAGA,MAAMA,QAAQ,GAAG,CAChB,CAAE,aAAF,CADgB,EAEhB,CAAE,0BAAF,CAFgB,EAGhB,CAAE,mBAAF,CAHgB,EAIhB,CAAE,sBAAF,CAJgB,EAKhB,CAAE,yBAAF,CALgB,EAMhB,CAAE,wBAAF,CANgB,CAAjB;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,sBA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H,GAEGL,gBAJc,CAAlB;;AAOA,MAAK,CAAEA,gBAAP,EAA0B;AACzB,WACC,iCAAQhB,UAAR,EACC,4BAAC,mBAAD,OADD,CADD;AAKA;;AAED,MAAK,CAAEM,MAAP,EAAgB;AACfc,IAAAA,WAAW,GAAGjD,sBAAsB,CAAE;AACrCC,MAAAA,OADqC;AAErCC,MAAAA,cAFqC;AAGrCC,MAAAA;AAHqC,KAAF,CAApC;AAKA;;AAED,MAAK,CAAE8C,WAAW,CAAC/B,MAAnB,EAA4B;AAC3B,WAAO,iCAAQW,UAAR,OAAwB,cAAI,mBAAJ,CAAxB,CAAP;AACA;;AAED,SACC,4BAAC,YAAD;AACC,IAAA,QAAQ,EAAGoB,WADZ;AAEC,IAAA,UAAU,EAAGpB,UAFd;AAGC,IAAA,MAAM,EAAGd,MAHV;AAIC,IAAA,eAAe,EAAGH,eAJnB;AAKC,IAAA,kBAAkB,EAAGC,kBALtB;AAMC,IAAA,cAAc,mBAAGoC,WAAW,CAAE,CAAF,CAAd,kDAAG,cAAkBzC;AANpC,IADD;AAUA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, memo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tBlockContextProvider,\n\tuseBlockProps,\n\tuseInnerBlocksProps,\n\tstore as blockEditorStore,\n\t__experimentalUseBlockPreview as useBlockPreview,\n} from '@wordpress/block-editor';\nimport { Spinner } from '@wordpress/components';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { useCommentQueryArgs, useCommentTree } from './hooks';\n\nconst TEMPLATE = [\n\t[ 'core/avatar' ],\n\t[ 'core/comment-author-name' ],\n\t[ 'core/comment-date' ],\n\t[ 'core/comment-content' ],\n\t[ 'core/comment-reply-link' ],\n\t[ 'core/comment-edit-link' ],\n];\n\n/**\n * Function that returns a comment structure that will be rendered with default placehoders.\n *\n * Each comment has a `commentId` property that is always a negative number in\n * case of the placeholders. This is to ensure that the comment does not\n * conflict with the actual (real) comments.\n *\n * @param {Object} settings Discussion Settings.\n * @param {number} [settings.perPage] - Comments per page setting or block attribute.\n * @param {boolean} [settings.threadComments] - Enable threaded (nested) comments setting.\n * @param {number} [settings.threadCommentsDepth] - Level deep of threaded comments.\n *\n * @typedef {{id: null, children: EmptyComment[]}} EmptyComment\n * @return {EmptyComment[]} \t\tInner blocks of the Comment Template\n */\nconst getCommentsPlaceholder = ( {\n\tperPage,\n\tthreadComments,\n\tthreadCommentsDepth,\n} ) => {\n\t// In case that `threadCommentsDepth` is falsy, we default to a somewhat\n\t// arbitrary value of 3.\n\t// In case that the value is set but larger than 3 we truncate it to 3.\n\tconst commentsDepth = Math.min( threadCommentsDepth || 3, 3 );\n\n\t// We set a limit in order not to overload the editor of empty comments.\n\tconst defaultCommentsToShow =\n\t\tperPage <= commentsDepth ? perPage : commentsDepth;\n\tif ( ! threadComments || defaultCommentsToShow === 1 ) {\n\t\t// If displaying threaded comments is disabled, we only show one comment\n\t\t// A commentId is negative in order to avoid conflicts with the actual comments.\n\t\treturn [ { commentId: -1, children: [] } ];\n\t} else if ( defaultCommentsToShow === 2 ) {\n\t\treturn [\n\t\t\t{\n\t\t\t\tcommentId: -1,\n\t\t\t\tchildren: [ { commentId: -2, children: [] } ],\n\t\t\t},\n\t\t];\n\t}\n\n\t// In case that the value is set but larger than 3 we truncate it to 3.\n\treturn [\n\t\t{\n\t\t\tcommentId: -1,\n\t\t\tchildren: [\n\t\t\t\t{\n\t\t\t\t\tcommentId: -2,\n\t\t\t\t\tchildren: [ { commentId: -3, children: [] } ],\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t];\n};\n\n/**\n * Component which renders the inner blocks of the Comment Template.\n *\n * @param {Object} props Component props.\n * @param {Array} [props.comment] - A comment object.\n * @param {Array} [props.activeCommentId] - The ID of the comment that is currently active.\n * @param {Array} [props.setActiveCommentId] - The setter for activeCommentId.\n * @param {Array} [props.firstCommentId] - ID of the first comment in the array.\n * @param {Array} [props.blocks] - Array of blocks returned from\n * getBlocks() in parent .\n * @return {WPElement} \t\tInner blocks of the Comment Template\n */\nfunction CommentTemplateInnerBlocks( {\n\tcomment,\n\tactiveCommentId,\n\tsetActiveCommentId,\n\tfirstCommentId,\n\tblocks,\n} ) {\n\tconst { children, ...innerBlocksProps } = useInnerBlocksProps(\n\t\t{},\n\t\t{ template: TEMPLATE }\n\t);\n\n\treturn (\n\t\t<li { ...innerBlocksProps }>\n\t\t\t{ comment.commentId === ( activeCommentId || firstCommentId )\n\t\t\t\t? children\n\t\t\t\t: null }\n\n\t\t\t{ /* To avoid flicker when switching active block contexts, a preview\n\t\t\tis ALWAYS rendered and the preview for the active block is hidden.\n\t\t\tThis ensures that when switching the active block, the component is not\n\t\t\tmounted again but rather it only toggles the `isHidden` prop.\n\n\t\t\tThe same strategy is used for preventing the flicker in the Post Template\n\t\t\tblock. */ }\n\t\t\t<MemoizedCommentTemplatePreview\n\t\t\t\tblocks={ blocks }\n\t\t\t\tcommentId={ comment.commentId }\n\t\t\t\tsetActiveCommentId={ setActiveCommentId }\n\t\t\t\tisHidden={\n\t\t\t\t\tcomment.commentId === ( activeCommentId || firstCommentId )\n\t\t\t\t}\n\t\t\t/>\n\n\t\t\t{ comment?.children?.length > 0 ? (\n\t\t\t\t<CommentsList\n\t\t\t\t\tcomments={ comment.children }\n\t\t\t\t\tactiveCommentId={ activeCommentId }\n\t\t\t\t\tsetActiveCommentId={ setActiveCommentId }\n\t\t\t\t\tblocks={ blocks }\n\t\t\t\t\tfirstCommentId={ firstCommentId }\n\t\t\t\t/>\n\t\t\t) : null }\n\t\t</li>\n\t);\n}\n\nconst CommentTemplatePreview = ( {\n\tblocks,\n\tcommentId,\n\tsetActiveCommentId,\n\tisHidden,\n} ) => {\n\tconst blockPreviewProps = useBlockPreview( {\n\t\tblocks,\n\t} );\n\n\tconst handleOnClick = () => {\n\t\tsetActiveCommentId( commentId );\n\t};\n\n\t// We have to hide the preview block if the `comment` props points to\n\t// the curently active block!\n\n\t// Or, to put it differently, every preview block is visible unless it is the\n\t// currently active block - in this case we render its inner blocks.\n\tconst style = {\n\t\tdisplay: isHidden ? 'none' : undefined,\n\t};\n\n\treturn (\n\t\t<div\n\t\t\t{ ...blockPreviewProps }\n\t\t\ttabIndex={ 0 }\n\t\t\trole=\"button\"\n\t\t\tstyle={ style }\n\t\t\t// eslint-disable-next-line jsx-a11y/no-noninteractive-element-to-interactive-role\n\t\t\tonClick={ handleOnClick }\n\t\t\tonKeyPress={ handleOnClick }\n\t\t/>\n\t);\n};\n\nconst MemoizedCommentTemplatePreview = memo( CommentTemplatePreview );\n\n/**\n * Component that renders a list of (nested) comments. It is called recursively.\n *\n * @param {Object} props Component props.\n * @param {Array} [props.comments] - Array of comment objects.\n * @param {Array} [props.blockProps] - Props from parent's `useBlockProps()`.\n * @param {Array} [props.activeCommentId] - The ID of the comment that is currently active.\n * @param {Array} [props.setActiveCommentId] - The setter for activeCommentId.\n * @param {Array} [props.blocks] - Array of blocks returned from getBlocks() in parent.\n * @param {Object} [props.firstCommentId] - The ID of the first comment in the array of\n * comment objects.\n * @return {WPElement} \t\tList of comments.\n */\nconst CommentsList = ( {\n\tcomments,\n\tblockProps,\n\tactiveCommentId,\n\tsetActiveCommentId,\n\tblocks,\n\tfirstCommentId,\n} ) => (\n\t<ol { ...blockProps }>\n\t\t{ comments &&\n\t\t\tcomments.map( ( { commentId, ...comment }, index ) => (\n\t\t\t\t<BlockContextProvider\n\t\t\t\t\tkey={ comment.commentId || index }\n\t\t\t\t\tvalue={ {\n\t\t\t\t\t\t// If the commentId is negative it means that this comment is a\n\t\t\t\t\t\t// \"placeholder\" and that the block is most likely being used in the\n\t\t\t\t\t\t// site editor. In this case, we have to set the commentId to `null`\n\t\t\t\t\t\t// because otherwise the (non-existent) comment with a negative ID\n\t\t\t\t\t\t// would be reqested from the REST API.\n\t\t\t\t\t\tcommentId: commentId < 0 ? null : commentId,\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t<CommentTemplateInnerBlocks\n\t\t\t\t\t\tcomment={ { commentId, ...comment } }\n\t\t\t\t\t\tactiveCommentId={ activeCommentId }\n\t\t\t\t\t\tsetActiveCommentId={ setActiveCommentId }\n\t\t\t\t\t\tblocks={ blocks }\n\t\t\t\t\t\tfirstCommentId={ firstCommentId }\n\t\t\t\t\t/>\n\t\t\t\t</BlockContextProvider>\n\t\t\t) ) }\n\t</ol>\n);\n\nexport default function CommentTemplateEdit( {\n\tclientId,\n\tcontext: {\n\t\tpostId,\n\t\t'comments/perPage': perPage,\n\t\t'comments/order': order,\n\t\t'comments/defaultPage': defaultPage,\n\t\t'comments/inherit': inherit,\n\t},\n} ) {\n\tconst blockProps = useBlockProps();\n\n\tconst [ activeCommentId, setActiveCommentId ] = useState();\n\tconst { commentOrder, threadCommentsDepth, threadComments } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getSettings } = select( blockEditorStore );\n\t\t\treturn getSettings().__experimentalDiscussionSettings;\n\t\t}\n\t);\n\n\tconst commentQuery = useCommentQueryArgs( {\n\t\tpostId,\n\t\tperPage,\n\t\tdefaultPage,\n\t\tinherit,\n\t} );\n\n\tconst { topLevelComments, blocks } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecords } = select( coreStore );\n\t\t\tconst { getBlocks } = select( blockEditorStore );\n\n\t\t\treturn {\n\t\t\t\t// Request only top-level comments. Replies are embedded.\n\t\t\t\ttopLevelComments: commentQuery\n\t\t\t\t\t? getEntityRecords( 'root', 'comment', commentQuery )\n\t\t\t\t\t: null,\n\t\t\t\tblocks: getBlocks( clientId ),\n\t\t\t};\n\t\t},\n\t\t[ clientId, commentQuery ]\n\t);\n\n\torder = inherit || ! order ? commentOrder : order;\n\n\t// Generate a tree structure of comment IDs.\n\tlet commentTree = useCommentTree(\n\t\t// Reverse the order of top comments if needed.\n\t\torder === 'desc' && topLevelComments\n\t\t\t? [ ...topLevelComments ].reverse()\n\t\t\t: topLevelComments\n\t);\n\n\tif ( ! topLevelComments ) {\n\t\treturn (\n\t\t\t<p { ...blockProps }>\n\t\t\t\t<Spinner />\n\t\t\t</p>\n\t\t);\n\t}\n\n\tif ( ! postId ) {\n\t\tcommentTree = getCommentsPlaceholder( {\n\t\t\tperPage,\n\t\t\tthreadComments,\n\t\t\tthreadCommentsDepth,\n\t\t} );\n\t}\n\n\tif ( ! commentTree.length ) {\n\t\treturn <p { ...blockProps }> { __( 'No results found.' ) }</p>;\n\t}\n\n\treturn (\n\t\t<CommentsList\n\t\t\tcomments={ commentTree }\n\t\t\tblockProps={ blockProps }\n\t\t\tblocks={ blocks }\n\t\t\tactiveCommentId={ activeCommentId }\n\t\t\tsetActiveCommentId={ setActiveCommentId }\n\t\t\tfirstCommentId={ commentTree[ 0 ]?.commentId }\n\t\t/>\n\t);\n}\n"]}
@@ -33,6 +33,8 @@ var _icons = require("@wordpress/icons");
33
33
 
34
34
  var _blob = require("@wordpress/blob");
35
35
 
36
+ var _notices = require("@wordpress/notices");
37
+
36
38
  var _shared = require("./shared");
37
39
 
38
40
  /**
@@ -74,8 +76,7 @@ function CoverHeightInput(_ref) {
74
76
  unit = 'px',
75
77
  value = ''
76
78
  } = _ref;
77
- const [temporaryInput, setTemporaryInput] = (0, _element.useState)(null);
78
- const instanceId = (0, _compose.useInstanceId)(_blockEditor.__experimentalUnitControl);
79
+ const instanceId = (0, _compose.useInstanceId)(_components.__experimentalUnitControl);
79
80
  const inputId = `block-cover-height-input-${instanceId}`;
80
81
  const isPx = unit === 'px';
81
82
  const units = (0, _components.__experimentalUseCustomUnits)({
@@ -94,38 +95,31 @@ function CoverHeightInput(_ref) {
94
95
  const inputValue = unprocessedValue !== '' ? parseFloat(unprocessedValue) : undefined;
95
96
 
96
97
  if (isNaN(inputValue) && inputValue !== undefined) {
97
- setTemporaryInput(unprocessedValue);
98
98
  return;
99
99
  }
100
100
 
101
- setTemporaryInput(null);
102
101
  onChange(inputValue);
103
102
  };
104
103
 
105
- const handleOnBlur = () => {
106
- if (temporaryInput !== null) {
107
- setTemporaryInput(null);
108
- }
109
- };
110
-
111
- const inputValue = temporaryInput !== null ? temporaryInput : value;
104
+ const computedValue = (0, _element.useMemo)(() => {
105
+ const [parsedQuantity] = (0, _components.__experimentalParseQuantityAndUnitFromRawValue)(value);
106
+ return [parsedQuantity, unit].join('');
107
+ }, [unit, value]);
112
108
  const min = isPx ? _shared.COVER_MIN_HEIGHT : 0;
113
109
  return (0, _element.createElement)(_components.BaseControl, {
114
110
  label: (0, _i18n.__)('Minimum height of cover'),
115
111
  id: inputId
116
- }, (0, _element.createElement)(_blockEditor.__experimentalUnitControl, {
112
+ }, (0, _element.createElement)(_components.__experimentalUnitControl, {
117
113
  id: inputId,
118
114
  isResetValueOnUnitChange: true,
119
115
  min: min,
120
- onBlur: handleOnBlur,
121
116
  onChange: handleOnChange,
122
117
  onUnitChange: onUnitChange,
123
118
  style: {
124
119
  maxWidth: 80
125
120
  },
126
- unit: unit,
127
121
  units: units,
128
- value: inputValue
122
+ value: computedValue
129
123
  }));
130
124
  }
131
125
 
@@ -247,15 +241,10 @@ function CoverPlaceholder(_ref4) {
247
241
  let {
248
242
  disableMediaButtons = false,
249
243
  children,
250
- noticeUI,
251
- noticeOperations,
252
244
  onSelectMedia,
245
+ onError,
253
246
  style
254
247
  } = _ref4;
255
- const {
256
- removeAllNotices,
257
- createErrorNotice
258
- } = noticeOperations;
259
248
  return (0, _element.createElement)(_blockEditor.MediaPlaceholder, {
260
249
  icon: (0, _element.createElement)(_blockEditor.BlockIcon, {
261
250
  icon: _icons.cover
@@ -267,12 +256,8 @@ function CoverPlaceholder(_ref4) {
267
256
  onSelect: onSelectMedia,
268
257
  accept: "image/*,video/*",
269
258
  allowedTypes: _shared.ALLOWED_MEDIA_TYPES,
270
- notices: noticeUI,
271
259
  disableMediaButtons: disableMediaButtons,
272
- onError: message => {
273
- removeAllNotices();
274
- createErrorNotice(message);
275
- },
260
+ onError: onError,
276
261
  style: style
277
262
  }, children);
278
263
  }
@@ -284,8 +269,6 @@ function CoverEdit(_ref5) {
284
269
  attributes,
285
270
  clientId,
286
271
  isSelected,
287
- noticeUI,
288
- noticeOperations,
289
272
  overlayColor,
290
273
  setAttributes,
291
274
  setOverlayColor,
@@ -311,6 +294,9 @@ function CoverEdit(_ref5) {
311
294
  const {
312
295
  __unstableMarkNextChangeAsNotPersistent
313
296
  } = (0, _data.useDispatch)(_blockEditor.store);
297
+ const {
298
+ createErrorNotice
299
+ } = (0, _data.useDispatch)(_notices.store);
314
300
  const {
315
301
  gradientClass,
316
302
  gradientValue,
@@ -363,6 +349,12 @@ function CoverEdit(_ref5) {
363
349
  });
364
350
  };
365
351
 
352
+ const onUploadError = message => {
353
+ createErrorNotice(Array.isArray(message) ? message[2] : message, {
354
+ type: 'snackbar'
355
+ });
356
+ };
357
+
366
358
  const isDarkElement = (0, _element.useRef)();
367
359
  const isCoverDark = useCoverIsDark(url, dimRatio, overlayColor.color, isDarkElement);
368
360
  (0, _element.useEffect)(() => {
@@ -526,9 +518,8 @@ function CoverEdit(_ref5) {
526
518
  return (0, _element.createElement)(_element.Fragment, null, controls, (0, _element.createElement)("div", (0, _extends2.default)({}, blockProps, {
527
519
  className: (0, _classnames.default)('is-placeholder', blockProps.className)
528
520
  }), (0, _element.createElement)(CoverPlaceholder, {
529
- noticeUI: noticeUI,
530
521
  onSelectMedia: onSelectMedia,
531
- noticeOperations: noticeOperations,
522
+ onError: onUploadError,
532
523
  style: {
533
524
  minHeight: minHeightWithUnit || undefined
534
525
  }
@@ -632,15 +623,14 @@ function CoverEdit(_ref5) {
632
623
  style: mediaStyle
633
624
  }), isUploadingMedia && (0, _element.createElement)(_components.Spinner, null), (0, _element.createElement)(CoverPlaceholder, {
634
625
  disableMediaButtons: true,
635
- noticeUI: noticeUI,
636
626
  onSelectMedia: onSelectMedia,
637
- noticeOperations: noticeOperations
627
+ onError: onUploadError
638
628
  }), (0, _element.createElement)("div", innerBlocksProps)));
639
629
  }
640
630
 
641
631
  var _default = (0, _compose.compose)([(0, _blockEditor.withColors)({
642
632
  overlayColor: 'background-color'
643
- }), _components.withNotices])(CoverEdit);
633
+ })])(CoverEdit);
644
634
 
645
635
  exports.default = _default;
646
636
  //# sourceMappingURL=edit.js.map