@wordpress/block-library 7.16.0 → 7.17.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 (235) hide show
  1. package/CHANGELOG.md +2 -1
  2. package/build/archives/edit.js +1 -0
  3. package/build/archives/edit.js.map +1 -1
  4. package/build/comment-template/edit.js +40 -32
  5. package/build/comment-template/edit.js.map +1 -1
  6. package/build/comments/edit/placeholder.js +1 -4
  7. package/build/comments/edit/placeholder.js.map +1 -1
  8. package/build/comments/index.js +5 -1
  9. package/build/comments/index.js.map +1 -1
  10. package/build/comments-title/edit.js +18 -1
  11. package/build/comments-title/edit.js.map +1 -1
  12. package/build/cover/edit/index.js +2 -2
  13. package/build/cover/edit/index.js.map +1 -1
  14. package/build/cover/edit/use-cover-is-dark.js +8 -7
  15. package/build/cover/edit/use-cover-is-dark.js.map +1 -1
  16. package/build/embed/variations.js +1 -1
  17. package/build/embed/variations.js.map +1 -1
  18. package/build/gallery/transforms.js +3 -3
  19. package/build/gallery/transforms.js.map +1 -1
  20. package/build/gallery/v1/edit.js +1 -1
  21. package/build/gallery/v1/edit.js.map +1 -1
  22. package/build/image/image.js +34 -10
  23. package/build/image/image.js.map +1 -1
  24. package/build/image/transforms.js +1 -7
  25. package/build/image/transforms.js.map +1 -1
  26. package/build/list/transforms.js +9 -1
  27. package/build/list/transforms.js.map +1 -1
  28. package/build/list-item/edit.js +3 -2
  29. package/build/list-item/edit.js.map +1 -1
  30. package/build/list-item/edit.native.js +3 -2
  31. package/build/list-item/edit.native.js.map +1 -1
  32. package/build/list-item/hooks/use-merge.js +19 -22
  33. package/build/list-item/hooks/use-merge.js.map +1 -1
  34. package/build/list-item/hooks/use-outdent-list-item.js +19 -3
  35. package/build/list-item/hooks/use-outdent-list-item.js.map +1 -1
  36. package/build/list-item/index.js +14 -1
  37. package/build/list-item/index.js.map +1 -1
  38. package/build/list-item/utils.js +14 -1
  39. package/build/list-item/utils.js.map +1 -1
  40. package/build/navigation/edit/index.js +35 -22
  41. package/build/navigation/edit/index.js.map +1 -1
  42. package/build/navigation/edit/inner-blocks.js +3 -5
  43. package/build/navigation/edit/inner-blocks.js.map +1 -1
  44. package/build/navigation/edit/use-convert-classic-menu-to-block-menu.js +25 -8
  45. package/build/navigation/edit/use-convert-classic-menu-to-block-menu.js.map +1 -1
  46. package/build/navigation/edit/use-create-navigation-menu.js +1 -1
  47. package/build/navigation/edit/use-create-navigation-menu.js.map +1 -1
  48. package/build/navigation/index.js +4 -1
  49. package/build/navigation/index.js.map +1 -1
  50. package/build/navigation-link/edit.js +1 -1
  51. package/build/navigation-link/edit.js.map +1 -1
  52. package/build/page-list/index.js +1 -5
  53. package/build/page-list/index.js.map +1 -1
  54. package/build/paragraph/edit.js +3 -11
  55. package/build/paragraph/edit.js.map +1 -1
  56. package/build/pattern/edit.js +11 -4
  57. package/build/pattern/edit.js.map +1 -1
  58. package/build/post-comments-form/form.js +1 -2
  59. package/build/post-comments-form/form.js.map +1 -1
  60. package/build/query/edit/inspector-controls/index.js +2 -2
  61. package/build/query/edit/inspector-controls/index.js.map +1 -1
  62. package/build/query/edit/inspector-controls/taxonomy-controls.js +79 -104
  63. package/build/query/edit/inspector-controls/taxonomy-controls.js.map +1 -1
  64. package/build/search/edit.js +2 -1
  65. package/build/search/edit.js.map +1 -1
  66. package/build/site-logo/edit.js +6 -9
  67. package/build/site-logo/edit.js.map +1 -1
  68. package/build/table/state.js +1 -1
  69. package/build/table/state.js.map +1 -1
  70. package/build/table-of-contents/edit.js +1 -4
  71. package/build/table-of-contents/edit.js.map +1 -1
  72. package/build/tag-cloud/edit.js +1 -1
  73. package/build/tag-cloud/edit.js.map +1 -1
  74. package/build/tag-cloud/index.js +8 -0
  75. package/build/tag-cloud/index.js.map +1 -1
  76. package/build-module/archives/edit.js +1 -0
  77. package/build-module/archives/edit.js.map +1 -1
  78. package/build-module/comment-template/edit.js +38 -30
  79. package/build-module/comment-template/edit.js.map +1 -1
  80. package/build-module/comments/edit/placeholder.js +1 -3
  81. package/build-module/comments/edit/placeholder.js.map +1 -1
  82. package/build-module/comments/index.js +5 -1
  83. package/build-module/comments/index.js.map +1 -1
  84. package/build-module/comments-title/edit.js +18 -2
  85. package/build-module/comments-title/edit.js.map +1 -1
  86. package/build-module/cover/edit/index.js +2 -2
  87. package/build-module/cover/edit/index.js.map +1 -1
  88. package/build-module/cover/edit/use-cover-is-dark.js +7 -7
  89. package/build-module/cover/edit/use-cover-is-dark.js.map +1 -1
  90. package/build-module/embed/variations.js +1 -1
  91. package/build-module/embed/variations.js.map +1 -1
  92. package/build-module/gallery/transforms.js +4 -4
  93. package/build-module/gallery/transforms.js.map +1 -1
  94. package/build-module/gallery/v1/edit.js +2 -2
  95. package/build-module/gallery/v1/edit.js.map +1 -1
  96. package/build-module/image/image.js +35 -11
  97. package/build-module/image/image.js.map +1 -1
  98. package/build-module/image/transforms.js +1 -6
  99. package/build-module/image/transforms.js.map +1 -1
  100. package/build-module/list/transforms.js +9 -1
  101. package/build-module/list/transforms.js.map +1 -1
  102. package/build-module/list-item/edit.js +3 -2
  103. package/build-module/list-item/edit.js.map +1 -1
  104. package/build-module/list-item/edit.native.js +3 -2
  105. package/build-module/list-item/edit.native.js.map +1 -1
  106. package/build-module/list-item/hooks/use-merge.js +19 -21
  107. package/build-module/list-item/hooks/use-merge.js.map +1 -1
  108. package/build-module/list-item/hooks/use-outdent-list-item.js +19 -3
  109. package/build-module/list-item/hooks/use-outdent-list-item.js.map +1 -1
  110. package/build-module/list-item/index.js +14 -1
  111. package/build-module/list-item/index.js.map +1 -1
  112. package/build-module/list-item/utils.js +14 -1
  113. package/build-module/list-item/utils.js.map +1 -1
  114. package/build-module/navigation/edit/index.js +35 -22
  115. package/build-module/navigation/edit/index.js.map +1 -1
  116. package/build-module/navigation/edit/inner-blocks.js +3 -5
  117. package/build-module/navigation/edit/inner-blocks.js.map +1 -1
  118. package/build-module/navigation/edit/use-convert-classic-menu-to-block-menu.js +25 -8
  119. package/build-module/navigation/edit/use-convert-classic-menu-to-block-menu.js.map +1 -1
  120. package/build-module/navigation/edit/use-create-navigation-menu.js +1 -1
  121. package/build-module/navigation/edit/use-create-navigation-menu.js.map +1 -1
  122. package/build-module/navigation/index.js +4 -1
  123. package/build-module/navigation/index.js.map +1 -1
  124. package/build-module/navigation-link/edit.js +1 -1
  125. package/build-module/navigation-link/edit.js.map +1 -1
  126. package/build-module/page-list/index.js +1 -5
  127. package/build-module/page-list/index.js.map +1 -1
  128. package/build-module/paragraph/edit.js +3 -10
  129. package/build-module/paragraph/edit.js.map +1 -1
  130. package/build-module/pattern/edit.js +10 -3
  131. package/build-module/pattern/edit.js.map +1 -1
  132. package/build-module/post-comments-form/form.js +2 -3
  133. package/build-module/post-comments-form/form.js.map +1 -1
  134. package/build-module/query/edit/inspector-controls/index.js +4 -4
  135. package/build-module/query/edit/inspector-controls/index.js.map +1 -1
  136. package/build-module/query/edit/inspector-controls/taxonomy-controls.js +81 -102
  137. package/build-module/query/edit/inspector-controls/taxonomy-controls.js.map +1 -1
  138. package/build-module/search/edit.js +3 -2
  139. package/build-module/search/edit.js.map +1 -1
  140. package/build-module/site-logo/edit.js +6 -9
  141. package/build-module/site-logo/edit.js.map +1 -1
  142. package/build-module/table/state.js +2 -2
  143. package/build-module/table/state.js.map +1 -1
  144. package/build-module/table-of-contents/edit.js +1 -3
  145. package/build-module/table-of-contents/edit.js.map +1 -1
  146. package/build-module/tag-cloud/edit.js +1 -1
  147. package/build-module/tag-cloud/edit.js.map +1 -1
  148. package/build-module/tag-cloud/index.js +8 -0
  149. package/build-module/tag-cloud/index.js.map +1 -1
  150. package/build-style/archives/style-rtl.css +4 -0
  151. package/build-style/archives/style.css +4 -0
  152. package/build-style/comments/editor-rtl.css +1 -0
  153. package/build-style/comments/editor.css +1 -0
  154. package/build-style/comments/style-rtl.css +1 -0
  155. package/build-style/comments/style.css +1 -0
  156. package/build-style/cover/editor-rtl.css +4 -0
  157. package/build-style/cover/editor.css +4 -0
  158. package/build-style/editor-rtl.css +9 -17
  159. package/build-style/editor.css +9 -17
  160. package/build-style/group/editor-rtl.css +1 -0
  161. package/build-style/group/editor.css +1 -0
  162. package/build-style/image/editor-rtl.css +1 -1
  163. package/build-style/image/editor.css +1 -1
  164. package/build-style/navigation/editor-rtl.css +1 -0
  165. package/build-style/navigation/editor.css +1 -0
  166. package/build-style/paragraph/editor-rtl.css +0 -16
  167. package/build-style/paragraph/editor.css +0 -16
  168. package/build-style/site-logo/editor-rtl.css +1 -0
  169. package/build-style/site-logo/editor.css +1 -0
  170. package/build-style/style-rtl.css +8 -0
  171. package/build-style/style.css +8 -0
  172. package/build-style/tag-cloud/style-rtl.css +3 -0
  173. package/build-style/tag-cloud/style.css +3 -0
  174. package/package.json +28 -28
  175. package/src/archives/edit.js +1 -0
  176. package/src/archives/style.scss +5 -0
  177. package/src/avatar/index.php +1 -1
  178. package/src/code/test/__snapshots__/edit.native.js.snap +13 -0
  179. package/src/code/test/edit.native.js +46 -32
  180. package/src/comment-template/edit.js +47 -34
  181. package/src/comments/block.json +5 -1
  182. package/src/comments/edit/placeholder.js +1 -7
  183. package/src/comments/style.scss +2 -0
  184. package/src/comments-title/edit.js +24 -1
  185. package/src/cover/edit/index.js +2 -7
  186. package/src/cover/edit/use-cover-is-dark.js +11 -11
  187. package/src/cover/editor.scss +7 -0
  188. package/src/embed/variations.js +1 -1
  189. package/src/gallery/transforms.js +8 -5
  190. package/src/gallery/v1/edit.js +2 -2
  191. package/src/group/editor.scss +1 -0
  192. package/src/image/editor.scss +4 -1
  193. package/src/image/image.js +59 -29
  194. package/src/image/transforms.js +1 -7
  195. package/src/list/test/edit.native.js +102 -3
  196. package/src/list/transforms.js +11 -0
  197. package/src/list-item/block.json +14 -1
  198. package/src/list-item/edit.js +2 -1
  199. package/src/list-item/edit.native.js +2 -1
  200. package/src/list-item/hooks/use-merge.js +4 -23
  201. package/src/list-item/hooks/use-outdent-list-item.js +6 -2
  202. package/src/navigation/block.json +4 -1
  203. package/src/navigation/edit/index.js +49 -23
  204. package/src/navigation/edit/inner-blocks.js +2 -5
  205. package/src/navigation/edit/use-convert-classic-menu-to-block-menu.js +32 -5
  206. package/src/navigation/edit/use-create-navigation-menu.js +2 -5
  207. package/src/navigation/editor.scss +1 -0
  208. package/src/navigation/index.php +103 -6
  209. package/src/navigation-link/edit.js +1 -1
  210. package/src/navigation-link/index.php +8 -1
  211. package/src/navigation-submenu/index.php +8 -1
  212. package/src/page-list/block.json +1 -5
  213. package/src/page-list/index.php +8 -6
  214. package/src/paragraph/edit.js +1 -14
  215. package/src/paragraph/editor.scss +0 -20
  216. package/src/pattern/edit.js +10 -3
  217. package/src/post-comments-form/form.js +2 -3
  218. package/src/query/edit/inspector-controls/index.js +4 -3
  219. package/src/query/edit/inspector-controls/taxonomy-controls.js +82 -87
  220. package/src/rss/index.php +3 -3
  221. package/src/search/edit.js +6 -1
  222. package/src/search/index.php +21 -13
  223. package/src/site-logo/edit.js +10 -8
  224. package/src/site-logo/editor.scss +1 -0
  225. package/src/table/state.js +2 -2
  226. package/src/table-of-contents/edit.js +1 -3
  227. package/src/tag-cloud/block.json +8 -0
  228. package/src/tag-cloud/edit.js +1 -1
  229. package/src/tag-cloud/style.scss +3 -0
  230. package/src/template-part/index.php +4 -0
  231. package/build/paragraph/drop-zone.js +0 -99
  232. package/build/paragraph/drop-zone.js.map +0 -1
  233. package/build-module/paragraph/drop-zone.js +0 -88
  234. package/build-module/paragraph/drop-zone.js.map +0 -1
  235. package/src/paragraph/drop-zone.js +0 -105
@@ -1,51 +1,65 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import renderer from 'react-test-renderer';
5
- import { TextInput } from 'react-native';
4
+ import {
5
+ fireEvent,
6
+ getEditorHtml,
7
+ initializeEditor,
8
+ addBlock,
9
+ getBlock,
10
+ } from 'test/helpers';
6
11
 
7
12
  /**
8
13
  * WordPress dependencies
9
14
  */
10
- import { BlockEdit } from '@wordpress/block-editor';
11
- import { registerBlockType, unregisterBlockType } from '@wordpress/blocks';
12
-
13
- /**
14
- * Internal dependencies
15
- */
16
- import { metadata, settings, name } from '../index';
17
-
18
- const Code = ( { clientId, ...props } ) => (
19
- <BlockEdit name={ name } clientId={ clientId || 0 } { ...props } />
20
- );
15
+ import { getBlockTypes, unregisterBlockType } from '@wordpress/blocks';
16
+ import { registerCoreBlocks } from '@wordpress/block-library';
21
17
 
22
18
  describe( 'Code', () => {
23
19
  beforeAll( () => {
24
- registerBlockType( name, {
25
- ...metadata,
26
- ...settings,
27
- } );
20
+ // Register all core blocks
21
+ registerCoreBlocks();
28
22
  } );
29
23
 
30
24
  afterAll( () => {
31
- unregisterBlockType( name );
25
+ // Clean up registered blocks
26
+ getBlockTypes().forEach( ( block ) => {
27
+ unregisterBlockType( block.name );
28
+ } );
32
29
  } );
33
30
 
34
- it( 'renders without crashing', () => {
35
- const component = renderer.create(
36
- <Code attributes={ { content: '' } } />
37
- );
38
- const rendered = component.toJSON();
39
- expect( rendered ).toBeTruthy();
31
+ it( 'renders without crashing', async () => {
32
+ const screen = await initializeEditor();
33
+
34
+ // Add block
35
+ await addBlock( screen, 'Code' );
36
+
37
+ // Get block
38
+ const codeBlock = await getBlock( screen, 'Code' );
39
+ expect( codeBlock ).toBeVisible();
40
+
41
+ expect( getEditorHtml() ).toMatchSnapshot();
40
42
  } );
41
43
 
42
- it( 'renders given text without crashing', () => {
43
- const component = renderer.create(
44
- <Code attributes={ { content: 'sample text' } } />
45
- );
46
- const testInstance = component.root;
47
- const textInput = testInstance.findByType( TextInput );
48
- expect( textInput ).toBeTruthy();
49
- expect( textInput.props.value ).toBe( 'sample text' );
44
+ it( 'renders given text without crashing', async () => {
45
+ const initialHtml = `<!-- wp:code -->
46
+ <pre class="wp-block-code"><code>Sample text</code></pre>
47
+ <!-- /wp:code -->`;
48
+
49
+ const screen = await initializeEditor( {
50
+ initialHtml,
51
+ } );
52
+ const { getByDisplayValue } = screen;
53
+
54
+ // Get block
55
+ const codeBlock = await getBlock( screen, 'Code' );
56
+ expect( codeBlock ).toBeVisible();
57
+ fireEvent.press( codeBlock );
58
+
59
+ // Get initial text
60
+ const codeBlockText = getByDisplayValue( 'Sample text' );
61
+ expect( codeBlockText ).toBeVisible();
62
+
63
+ expect( getEditorHtml() ).toMatchSnapshot();
50
64
  } );
51
65
  } );
@@ -37,6 +37,7 @@ const TEMPLATE = [
37
37
  *
38
38
  * @param {Object} settings Discussion Settings.
39
39
  * @param {number} [settings.perPage] - Comments per page setting or block attribute.
40
+ * @param {boolean} [settings.pageComments] - Enable break comments into pages setting.
40
41
  * @param {boolean} [settings.threadComments] - Enable threaded (nested) comments setting.
41
42
  * @param {number} [settings.threadCommentsDepth] - Level deep of threaded comments.
42
43
  *
@@ -45,42 +46,53 @@ const TEMPLATE = [
45
46
  */
46
47
  const getCommentsPlaceholder = ( {
47
48
  perPage,
49
+ pageComments,
48
50
  threadComments,
49
51
  threadCommentsDepth,
50
52
  } ) => {
51
- // In case that `threadCommentsDepth` is falsy, we default to a somewhat
52
- // arbitrary value of 3.
53
- // In case that the value is set but larger than 3 we truncate it to 3.
54
- const commentsDepth = Math.min( threadCommentsDepth || 3, 3 );
53
+ // Limit commentsDepth to 3
54
+ const commentsDepth = ! threadComments
55
+ ? 1
56
+ : Math.min( threadCommentsDepth, 3 );
55
57
 
56
- // We set a limit in order not to overload the editor of empty comments.
57
- const defaultCommentsToShow =
58
- perPage <= commentsDepth ? perPage : commentsDepth;
59
- if ( ! threadComments || defaultCommentsToShow === 1 ) {
60
- // If displaying threaded comments is disabled, we only show one comment
61
- // A commentId is negative in order to avoid conflicts with the actual comments.
62
- return [ { commentId: -1, children: [] } ];
63
- } else if ( defaultCommentsToShow === 2 ) {
64
- return [
65
- {
66
- commentId: -1,
67
- children: [ { commentId: -2, children: [] } ],
68
- },
69
- ];
70
- }
58
+ const buildChildrenComment = ( commentsLevel ) => {
59
+ // Render children comments until commentsDepth is reached
60
+ if ( commentsLevel < commentsDepth ) {
61
+ const nextLevel = commentsLevel + 1;
71
62
 
72
- // In case that the value is set but larger than 3 we truncate it to 3.
73
- return [
74
- {
75
- commentId: -1,
76
- children: [
63
+ return [
77
64
  {
78
- commentId: -2,
79
- children: [ { commentId: -3, children: [] } ],
65
+ commentId: -( commentsLevel + 3 ),
66
+ children: buildChildrenComment( nextLevel ),
80
67
  },
81
- ],
82
- },
68
+ ];
69
+ }
70
+ return [];
71
+ };
72
+
73
+ // Add the first comment and its children
74
+ const placeholderComments = [
75
+ { commentId: -1, children: buildChildrenComment( 1 ) },
83
76
  ];
77
+
78
+ // Add a second comment unless the break comments setting is active and set to less than 2, and there is one nested comment max
79
+ if ( ( ! pageComments || perPage >= 2 ) && commentsDepth < 3 ) {
80
+ placeholderComments.push( {
81
+ commentId: -2,
82
+ children: [],
83
+ } );
84
+ }
85
+
86
+ // Add a third comment unless the break comments setting is active and set to less than 3, and there aren't nested comments
87
+ if ( ( ! pageComments || perPage >= 3 ) && commentsDepth < 2 ) {
88
+ placeholderComments.push( {
89
+ commentId: -3,
90
+ children: [],
91
+ } );
92
+ }
93
+
94
+ // In case that the value is set but larger than 3 we truncate it to 3.
95
+ return placeholderComments;
84
96
  };
85
97
 
86
98
  /**
@@ -114,12 +126,11 @@ function CommentTemplateInnerBlocks( {
114
126
  : null }
115
127
 
116
128
  { /* To avoid flicker when switching active block contexts, a preview
117
- is ALWAYS rendered and the preview for the active block is hidden.
118
- This ensures that when switching the active block, the component is not
119
- mounted again but rather it only toggles the `isHidden` prop.
120
-
121
- The same strategy is used for preventing the flicker in the Post Template
122
- block. */ }
129
+ is ALWAYS rendered and the preview for the active block is hidden.
130
+ This ensures that when switching the active block, the component is not
131
+ mounted again but rather it only toggles the `isHidden` prop.
132
+ The same strategy is used for preventing the flicker in the Post Template
133
+ block. */ }
123
134
  <MemoizedCommentTemplatePreview
124
135
  blocks={ blocks }
125
136
  commentId={ comment.commentId }
@@ -239,6 +250,7 @@ export default function CommentTemplateEdit( {
239
250
  threadCommentsDepth,
240
251
  threadComments,
241
252
  commentsPerPage,
253
+ pageComments,
242
254
  } = useSelect( ( select ) => {
243
255
  const { getSettings } = select( blockEditorStore );
244
256
  return getSettings().__experimentalDiscussionSettings;
@@ -282,6 +294,7 @@ export default function CommentTemplateEdit( {
282
294
  if ( ! postId ) {
283
295
  commentTree = getCommentsPlaceholder( {
284
296
  perPage: commentsPerPage,
297
+ pageComments,
285
298
  threadComments,
286
299
  threadCommentsDepth,
287
300
  } );
@@ -18,7 +18,6 @@
18
18
  },
19
19
  "supports": {
20
20
  "align": [ "wide", "full" ],
21
- "html": false,
22
21
  "color": {
23
22
  "gradients": true,
24
23
  "link": true,
@@ -28,6 +27,11 @@
28
27
  "link": true
29
28
  }
30
29
  },
30
+ "html": false,
31
+ "spacing": {
32
+ "margin": true,
33
+ "padding": true
34
+ },
31
35
  "typography": {
32
36
  "fontSize": true,
33
37
  "lineHeight": true,
@@ -5,7 +5,6 @@ import { store as blockEditorStore } from '@wordpress/block-editor';
5
5
  import { __, sprintf } from '@wordpress/i18n';
6
6
  import { useSelect } from '@wordpress/data';
7
7
  import { useEntityProp } from '@wordpress/core-data';
8
- import { useDisabled } from '@wordpress/compose';
9
8
 
10
9
  /**
11
10
  * Internal dependencies
@@ -22,13 +21,8 @@ export default function PostCommentsPlaceholder( { postType, postId } ) {
22
21
  .__experimentalDiscussionSettings
23
22
  );
24
23
 
25
- const disabledRef = useDisabled();
26
-
27
24
  return (
28
- <div
29
- className="wp-block-comments__legacy-placeholder"
30
- ref={ disabledRef }
31
- >
25
+ <div className="wp-block-comments__legacy-placeholder" inert="true">
32
26
  <h3>
33
27
  {
34
28
  /* translators: %s: Post title. */
@@ -1,5 +1,7 @@
1
1
  /* Styles for backwards compatibility with the legacy `post-comments` block */
2
2
  .wp-block-post-comments {
3
+ // This block has customizable padding, border-box makes that more predictable.
4
+ box-sizing: border-box;
3
5
 
4
6
  /* utility classes */
5
7
  .alignleft {
@@ -11,11 +11,13 @@ import {
11
11
  BlockControls,
12
12
  useBlockProps,
13
13
  InspectorControls,
14
+ store as blockEditorStore,
14
15
  } from '@wordpress/block-editor';
15
16
  import { __, _n, sprintf } from '@wordpress/i18n';
16
17
  import { useEntityProp } from '@wordpress/core-data';
17
18
  import { PanelBody, ToggleControl } from '@wordpress/components';
18
19
  import { useState, useEffect } from '@wordpress/element';
20
+ import { useSelect } from '@wordpress/data';
19
21
  import apiFetch from '@wordpress/api-fetch';
20
22
  import { addQueryArgs } from '@wordpress/url';
21
23
 
@@ -39,9 +41,30 @@ export default function Edit( {
39
41
  } ),
40
42
  } );
41
43
 
44
+ const {
45
+ threadCommentsDepth,
46
+ threadComments,
47
+ commentsPerPage,
48
+ pageComments,
49
+ } = useSelect( ( select ) => {
50
+ const { getSettings } = select( blockEditorStore );
51
+ return getSettings().__experimentalDiscussionSettings;
52
+ } );
53
+
42
54
  useEffect( () => {
43
55
  if ( isSiteEditor ) {
44
- setCommentsCount( 3 );
56
+ // Match the number of comments that will be shown in the comment-template/edit.js placeholder
57
+
58
+ const nestedCommentsNumber = threadComments
59
+ ? Math.min( threadCommentsDepth, 3 ) - 1
60
+ : 0;
61
+ const topLevelCommentsNumber = pageComments ? commentsPerPage : 3;
62
+
63
+ const commentsNumber =
64
+ parseInt( nestedCommentsNumber ) +
65
+ parseInt( topLevelCommentsNumber );
66
+
67
+ setCommentsCount( Math.min( commentsNumber, 3 ) );
45
68
  return;
46
69
  }
47
70
  const currentPostId = postId;
@@ -131,13 +131,7 @@ function CoverEdit( {
131
131
  createErrorNotice( message, { type: 'snackbar' } );
132
132
  };
133
133
 
134
- const mediaElement = useRef();
135
- const isCoverDark = useCoverIsDark(
136
- url,
137
- dimRatio,
138
- overlayColor.color,
139
- mediaElement
140
- );
134
+ const isCoverDark = useCoverIsDark( url, dimRatio, overlayColor.color );
141
135
 
142
136
  useEffect( () => {
143
137
  // This side-effect should not create an undo level.
@@ -201,6 +195,7 @@ function CoverEdit( {
201
195
  }
202
196
  );
203
197
 
198
+ const mediaElement = useRef();
204
199
  const currentSettings = {
205
200
  isVideoBackground,
206
201
  isImageBackground,
@@ -8,6 +8,7 @@ import { colord } from 'colord';
8
8
  * WordPress dependencies
9
9
  */
10
10
  import { useEffect, useState } from '@wordpress/element';
11
+ import { applyFilters } from '@wordpress/hooks';
11
12
 
12
13
  function retrieveFastAverageColor() {
13
14
  if ( ! retrieveFastAverageColor.fastAverageColor ) {
@@ -25,34 +26,33 @@ function retrieveFastAverageColor() {
25
26
  * color are set, dimRatio is used to decide what is used
26
27
  * for background darkness checking purposes.
27
28
  * @param {?string} overlayColor String containing the overlay color value if one exists.
28
- * @param {?Object} elementRef If a media background is set, elementRef should contain a reference to a
29
- * dom element that renders that media.
30
29
  *
31
30
  * @return {boolean} True if the cover background is considered "dark" and false otherwise.
32
31
  */
33
- export default function useCoverIsDark(
34
- url,
35
- dimRatio = 50,
36
- overlayColor,
37
- elementRef
38
- ) {
32
+ export default function useCoverIsDark( url, dimRatio = 50, overlayColor ) {
39
33
  const [ isDark, setIsDark ] = useState( false );
40
34
  useEffect( () => {
41
35
  // If opacity is lower than 50 the dominant color is the image or video color,
42
36
  // so use that color for the dark mode computation.
43
- if ( url && dimRatio <= 50 && elementRef.current ) {
37
+ if ( url && dimRatio <= 50 ) {
38
+ const imgCrossOrigin = applyFilters(
39
+ 'media.crossOrigin',
40
+ undefined,
41
+ url
42
+ );
44
43
  retrieveFastAverageColor()
45
- .getColorAsync( elementRef.current, {
44
+ .getColorAsync( url, {
46
45
  // Previously the default color was white, but that changed
47
46
  // in v6.0.0 so it has to be manually set now.
48
47
  defaultColor: [ 255, 255, 255, 255 ],
49
48
  // Errors that come up don't reject the promise, so error
50
49
  // logging has to be silenced with this option.
51
50
  silent: process.env.NODE_ENV === 'production',
51
+ crossOrigin: imgCrossOrigin,
52
52
  } )
53
53
  .then( ( color ) => setIsDark( color.isDark ) );
54
54
  }
55
- }, [ url, url && dimRatio <= 50 && elementRef.current, setIsDark ] );
55
+ }, [ url, url && dimRatio <= 50, setIsDark ] );
56
56
  useEffect( () => {
57
57
  // If opacity is greater than 50 the dominant color is the overlay color,
58
58
  // so use that color for the dark mode computation.
@@ -107,3 +107,10 @@
107
107
  .color-block-support-panel__inner-wrapper > :not(.block-editor-tools-panel-color-gradient-settings__item) {
108
108
  margin-top: $grid-unit-30;
109
109
  }
110
+
111
+
112
+ // The frontend style.scss includes a min-height as an IE11 fix.
113
+ // This fix causes extra spacing for the focus style in the editor, so we omit it here.
114
+ .wp-block-cover::after {
115
+ min-height: auto;
116
+ }
@@ -309,7 +309,7 @@ const variations = [
309
309
  icon: embedTumblrIcon,
310
310
  keywords: [ __( 'social' ) ],
311
311
  description: __( 'Embed a Tumblr post.' ),
312
- patterns: [ /^https?:\/\/(www\.)?tumblr\.com\/.+/i ],
312
+ patterns: [ /^https?:\/\/(.+)\.tumblr\.com\/.+/i ],
313
313
  attributes: { providerNameSlug: 'tumblr', responsive: true },
314
314
  },
315
315
  {
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { filter, every } from 'lodash';
4
+ import { filter } from 'lodash';
5
5
 
6
6
  /**
7
7
  * WordPress dependencies
@@ -133,10 +133,14 @@ const transforms = {
133
133
  // Init the align and size from the first item which may be either the placeholder or an image.
134
134
  let { align, sizeSlug } = attributes[ 0 ];
135
135
  // Loop through all the images and check if they have the same align and size.
136
- align = every( attributes, [ 'align', align ] )
136
+ align = attributes.every(
137
+ ( attribute ) => attribute.align === align
138
+ )
137
139
  ? align
138
140
  : undefined;
139
- sizeSlug = every( attributes, [ 'sizeSlug', sizeSlug ] )
141
+ sizeSlug = attributes.every(
142
+ ( attribute ) => attribute.sizeSlug === sizeSlug
143
+ )
140
144
  ? sizeSlug
141
145
  : undefined;
142
146
 
@@ -268,8 +272,7 @@ const transforms = {
268
272
  isMatch( files ) {
269
273
  return (
270
274
  files.length !== 1 &&
271
- every(
272
- files,
275
+ files.every(
273
276
  ( file ) => file.type.indexOf( 'image/' ) === 0
274
277
  )
275
278
  );
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { every, filter, find, get, isEmpty, map, reduce, some } from 'lodash';
4
+ import { filter, find, get, isEmpty, map, reduce, some } from 'lodash';
5
5
 
6
6
  /**
7
7
  * WordPress dependencies
@@ -333,7 +333,7 @@ function GalleryEdit( props ) {
333
333
  Platform.OS === 'web' &&
334
334
  images &&
335
335
  images.length > 0 &&
336
- every( images, ( { url } ) => isBlobURL( url ) )
336
+ images.every( ( { url } ) => isBlobURL( url ) )
337
337
  ) {
338
338
  const filesList = map( images, ( { url } ) => getBlobByURL( url ) );
339
339
  images.forEach( ( { url } ) => revokeBlobURL( url ) );
@@ -42,6 +42,7 @@
42
42
  flex: 1 0 $grid-unit-60;
43
43
  pointer-events: none;
44
44
  min-height: $grid-unit-60 - $border-width - $border-width;
45
+ border: $border-width dashed currentColor;
45
46
  @include placeholder-style();
46
47
  }
47
48
 
@@ -66,7 +66,10 @@ figure.wp-block-image:not(.wp-block) {
66
66
 
67
67
  // This is necessary for the editor resize handles to accurately work on a non-floated, non-resized, small image.
68
68
  .wp-block-image .components-resizable-box__container {
69
- display: inline-block;
69
+ // Using "display: table" because:
70
+ // - it visually hides empty white space in between elements
71
+ // - it allows the element to be as wide as its contents (instead of 100% width, as it would be with `display: block`)
72
+ display: table;
70
73
  img {
71
74
  display: block;
72
75
  width: inherit;
@@ -40,7 +40,12 @@ import {
40
40
  getDefaultBlockName,
41
41
  switchToBlockType,
42
42
  } from '@wordpress/blocks';
43
- import { crop, overlayText, upload } from '@wordpress/icons';
43
+ import {
44
+ crop,
45
+ overlayText,
46
+ upload,
47
+ caption as captionIcon,
48
+ } from '@wordpress/icons';
44
49
  import { store as noticesStore } from '@wordpress/notices';
45
50
  import { store as coreStore } from '@wordpress/core-data';
46
51
 
@@ -89,7 +94,8 @@ export default function Image( {
89
94
  } = attributes;
90
95
  const imageRef = useRef();
91
96
  const captionRef = useRef();
92
- const prevUrl = usePrevious( url );
97
+ const prevCaption = usePrevious( caption );
98
+ const [ showCaption, setShowCaption ] = useState( !! caption );
93
99
  const { allowResize = true } = context;
94
100
  const { getBlock } = useSelect( blockEditorStore );
95
101
 
@@ -180,15 +186,20 @@ export default function Image( {
180
186
  .catch( () => {} );
181
187
  }, [ id, url, isSelected, externalBlob ] );
182
188
 
183
- // Focus the caption after inserting an image from the placeholder. This is
184
- // done to preserve the behaviour of focussing the first tabbable element
185
- // when a block is mounted. Previously, the image block would remount when
186
- // the placeholder is removed. Maybe this behaviour could be removed.
189
+ // We need to show the caption when changes come from
190
+ // history navigation(undo/redo).
191
+ useEffect( () => {
192
+ if ( caption && ! prevCaption ) {
193
+ setShowCaption( true );
194
+ }
195
+ }, [ caption, prevCaption ] );
196
+
197
+ // Focus the caption when we click to add one.
187
198
  useEffect( () => {
188
- if ( url && ! prevUrl && isSelected ) {
189
- captionRef.current.focus();
199
+ if ( showCaption && ! caption ) {
200
+ captionRef.current?.focus();
190
201
  }
191
- }, [ url, prevUrl ] );
202
+ }, [ caption, showCaption ] );
192
203
 
193
204
  // Get naturalWidth and naturalHeight from image ref, and fall back to loaded natural
194
205
  // width and height. This resolves an issue in Safari where the loaded natural
@@ -297,8 +308,11 @@ export default function Image( {
297
308
  useEffect( () => {
298
309
  if ( ! isSelected ) {
299
310
  setIsEditingImage( false );
311
+ if ( ! caption ) {
312
+ setShowCaption( false );
313
+ }
300
314
  }
301
- }, [ isSelected ] );
315
+ }, [ isSelected, caption ] );
302
316
 
303
317
  const canEditImage = id && naturalWidth && naturalHeight && imageEditing;
304
318
  const allowCrop = ! multiImageSelection && canEditImage && ! isEditingImage;
@@ -319,6 +333,19 @@ export default function Image( {
319
333
  onChange={ updateAlignment }
320
334
  />
321
335
  ) }
336
+ { ! isContentLocked && (
337
+ <ToolbarButton
338
+ onClick={ () => {
339
+ setShowCaption( ! showCaption );
340
+ if ( showCaption && caption ) {
341
+ setAttributes( { caption: undefined } );
342
+ }
343
+ } }
344
+ icon={ captionIcon }
345
+ isPressed={ showCaption }
346
+ label={ __( 'Caption' ) }
347
+ />
348
+ ) }
322
349
  { ! multiImageSelection && ! isEditingImage && (
323
350
  <ImageURLInputUI
324
351
  url={ href || '' }
@@ -591,25 +618,28 @@ export default function Image( {
591
618
  which causes duplicated image upload. */ }
592
619
  { ! temporaryURL && controls }
593
620
  { img }
594
- { ( ! RichText.isEmpty( caption ) || isSelected ) && (
595
- <RichText
596
- className={ __experimentalGetElementClassName( 'caption' ) }
597
- ref={ captionRef }
598
- tagName="figcaption"
599
- aria-label={ __( 'Image caption text' ) }
600
- placeholder={ __( 'Add caption' ) }
601
- value={ caption }
602
- onChange={ ( value ) =>
603
- setAttributes( { caption: value } )
604
- }
605
- inlineToolbar
606
- __unstableOnSplitAtEnd={ () =>
607
- insertBlocksAfter(
608
- createBlock( getDefaultBlockName() )
609
- )
610
- }
611
- />
612
- ) }
621
+ { showCaption &&
622
+ ( ! RichText.isEmpty( caption ) || isSelected ) && (
623
+ <RichText
624
+ className={ __experimentalGetElementClassName(
625
+ 'caption'
626
+ ) }
627
+ ref={ captionRef }
628
+ tagName="figcaption"
629
+ aria-label={ __( 'Image caption text' ) }
630
+ placeholder={ __( 'Add caption' ) }
631
+ value={ caption }
632
+ onChange={ ( value ) =>
633
+ setAttributes( { caption: value } )
634
+ }
635
+ inlineToolbar
636
+ __unstableOnSplitAtEnd={ () =>
637
+ insertBlocksAfter(
638
+ createBlock( getDefaultBlockName() )
639
+ )
640
+ }
641
+ />
642
+ ) }
613
643
  </ImageEditingProvider>
614
644
  );
615
645
  }
@@ -1,8 +1,3 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { every } from 'lodash';
5
-
6
1
  /**
7
2
  * WordPress dependencies
8
3
  */
@@ -157,8 +152,7 @@ const transforms = {
157
152
  }
158
153
  );
159
154
  }
160
- return every(
161
- files,
155
+ return files.every(
162
156
  ( file ) => file.type.indexOf( 'image/' ) === 0
163
157
  );
164
158
  },