@wordpress/block-library 7.14.4 → 7.14.5

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 (45) hide show
  1. package/build/comment-template/edit.js +40 -32
  2. package/build/comment-template/edit.js.map +1 -1
  3. package/build/comments-title/edit.js +18 -1
  4. package/build/comments-title/edit.js.map +1 -1
  5. package/build/group/edit.js +1 -1
  6. package/build/group/edit.js.map +1 -1
  7. package/build/list/transforms.js +9 -1
  8. package/build/list/transforms.js.map +1 -1
  9. package/build/list-item/edit.js +3 -2
  10. package/build/list-item/edit.js.map +1 -1
  11. package/build/list-item/hooks/use-merge.js +5 -21
  12. package/build/list-item/hooks/use-merge.js.map +1 -1
  13. package/build/navigation/index.js +0 -1
  14. package/build/navigation/index.js.map +1 -1
  15. package/build/page-list/index.js +1 -5
  16. package/build/page-list/index.js.map +1 -1
  17. package/build-module/comment-template/edit.js +38 -30
  18. package/build-module/comment-template/edit.js.map +1 -1
  19. package/build-module/comments-title/edit.js +18 -2
  20. package/build-module/comments-title/edit.js.map +1 -1
  21. package/build-module/group/edit.js +1 -1
  22. package/build-module/group/edit.js.map +1 -1
  23. package/build-module/list/transforms.js +9 -1
  24. package/build-module/list/transforms.js.map +1 -1
  25. package/build-module/list-item/edit.js +3 -2
  26. package/build-module/list-item/edit.js.map +1 -1
  27. package/build-module/list-item/hooks/use-merge.js +5 -20
  28. package/build-module/list-item/hooks/use-merge.js.map +1 -1
  29. package/build-module/navigation/index.js +0 -1
  30. package/build-module/navigation/index.js.map +1 -1
  31. package/build-module/page-list/index.js +1 -5
  32. package/build-module/page-list/index.js.map +1 -1
  33. package/package.json +4 -4
  34. package/src/comment-author-name/index.php +1 -1
  35. package/src/comment-template/edit.js +47 -34
  36. package/src/comments-title/edit.js +24 -1
  37. package/src/group/edit.js +1 -1
  38. package/src/list/transforms.js +11 -0
  39. package/src/list-item/edit.js +2 -1
  40. package/src/list-item/hooks/use-merge.js +4 -23
  41. package/src/navigation/block.json +0 -1
  42. package/src/navigation/index.php +0 -3
  43. package/src/page-list/block.json +1 -5
  44. package/src/page-list/index.php +0 -5
  45. package/src/template-part/index.php +4 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/block-library",
3
- "version": "7.14.4",
3
+ "version": "7.14.5",
4
4
  "description": "Block library for the WordPress editor.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -35,7 +35,7 @@
35
35
  "@wordpress/api-fetch": "^6.14.1",
36
36
  "@wordpress/autop": "^3.17.1",
37
37
  "@wordpress/blob": "^3.17.1",
38
- "@wordpress/block-editor": "^10.0.4",
38
+ "@wordpress/block-editor": "^10.0.5",
39
39
  "@wordpress/blocks": "^11.16.4",
40
40
  "@wordpress/components": "^21.0.4",
41
41
  "@wordpress/compose": "^5.15.2",
@@ -52,7 +52,7 @@
52
52
  "@wordpress/keycodes": "^3.17.1",
53
53
  "@wordpress/notices": "^3.17.3",
54
54
  "@wordpress/primitives": "^3.15.1",
55
- "@wordpress/reusable-blocks": "^3.15.4",
55
+ "@wordpress/reusable-blocks": "^3.15.5",
56
56
  "@wordpress/rich-text": "^5.15.3",
57
57
  "@wordpress/server-side-render": "^3.15.4",
58
58
  "@wordpress/url": "^3.18.1",
@@ -73,5 +73,5 @@
73
73
  "publishConfig": {
74
74
  "access": "public"
75
75
  },
76
- "gitHead": "491b4b522dffb4d25aca066ec55500f456ac4aa3"
76
+ "gitHead": "06334a7bd943f2345f15b8d2f427721d6878e6c1"
77
77
  }
@@ -34,7 +34,7 @@ function render_block_core_comment_author_name( $attributes, $content, $block )
34
34
  $comment_author = get_comment_author( $comment );
35
35
  $link = get_comment_author_url( $comment );
36
36
 
37
- if ( ! empty( $attributes['isLink'] ) && ! empty( $attributes['linkTarget'] ) ) {
37
+ if ( ! empty( $link ) && ! empty( $attributes['isLink'] ) && ! empty( $attributes['linkTarget'] ) ) {
38
38
  $comment_author = sprintf( '<a rel="external nofollow ugc" href="%1s" target="%2s" >%3s</a>', esc_url( $link ), esc_attr( $attributes['linkTarget'] ), $comment_author );
39
39
  }
40
40
  if ( '0' === $comment->comment_approved && ! $show_pending_links ) {
@@ -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
  } );
@@ -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;
package/src/group/edit.js CHANGED
@@ -53,7 +53,7 @@ function GroupEdit( { attributes, setAttributes, clientId } ) {
53
53
  ? { ...defaultLayout, ...layout, type: 'default' }
54
54
  : { ...defaultLayout, ...layout };
55
55
  const { type = 'default' } = usedLayout;
56
- const layoutSupportEnabled = themeSupportsLayout || type !== 'default';
56
+ const layoutSupportEnabled = themeSupportsLayout || type === 'flex';
57
57
 
58
58
  const blockProps = useBlockProps();
59
59
 
@@ -114,6 +114,17 @@ const transforms = {
114
114
  );
115
115
  },
116
116
  } ) ),
117
+ {
118
+ type: 'block',
119
+ blocks: [ '*' ],
120
+ transform: ( _attributes, childBlocks ) => {
121
+ return getListContentFlat( childBlocks ).map( ( content ) =>
122
+ createBlock( 'core/paragraph', {
123
+ content,
124
+ } )
125
+ );
126
+ },
127
+ },
117
128
  ],
118
129
  };
119
130
 
@@ -60,6 +60,7 @@ export default function ListItemEdit( {
60
60
  setAttributes,
61
61
  onReplace,
62
62
  clientId,
63
+ mergeBlocks,
63
64
  } ) {
64
65
  const { placeholder, content } = attributes;
65
66
  const blockProps = useBlockProps( { ref: useCopy( clientId ) } );
@@ -69,7 +70,7 @@ export default function ListItemEdit( {
69
70
  const useEnterRef = useEnter( { content, clientId } );
70
71
  const useSpaceRef = useSpace( clientId );
71
72
  const onSplit = useSplit( clientId );
72
- const onMerge = useMerge( clientId );
73
+ const onMerge = useMerge( clientId, mergeBlocks );
73
74
  return (
74
75
  <>
75
76
  <li { ...innerBlocksProps }>
@@ -3,7 +3,6 @@
3
3
  */
4
4
  import { useRegistry, useDispatch, useSelect } from '@wordpress/data';
5
5
  import { store as blockEditorStore } from '@wordpress/block-editor';
6
- import { getDefaultBlockName, switchToBlockType } from '@wordpress/blocks';
7
6
 
8
7
  /**
9
8
  * Internal dependencies
@@ -12,7 +11,7 @@ import useOutdentListItem from './use-outdent-list-item';
12
11
 
13
12
  import { name as listItemName } from '../block.json';
14
13
 
15
- export default function useMerge( clientId ) {
14
+ export default function useMerge( clientId, onMerge ) {
16
15
  const registry = useRegistry();
17
16
  const {
18
17
  getPreviousBlockClientId,
@@ -20,9 +19,8 @@ export default function useMerge( clientId ) {
20
19
  getBlockOrder,
21
20
  getBlockRootClientId,
22
21
  getBlockName,
23
- getBlock,
24
22
  } = useSelect( blockEditorStore );
25
- const { mergeBlocks, moveBlocksToPosition, replaceBlock, selectBlock } =
23
+ const { mergeBlocks, moveBlocksToPosition } =
26
24
  useDispatch( blockEditorStore );
27
25
  const [ , outdentListItem ] = useOutdentListItem( clientId );
28
26
 
@@ -79,29 +77,12 @@ export default function useMerge( clientId ) {
79
77
  return getBlockOrder( order[ 0 ] )[ 0 ];
80
78
  }
81
79
 
82
- function switchToDefaultBlockType( forward ) {
83
- const rootClientId = getBlockRootClientId( clientId );
84
- const replacement = switchToBlockType(
85
- getBlock( rootClientId ),
86
- getDefaultBlockName()
87
- );
88
- const indexToSelect = forward ? replacement.length - 1 : 0;
89
- const initialPosition = forward ? -1 : 0;
90
- registry.batch( () => {
91
- replaceBlock( rootClientId, replacement );
92
- selectBlock(
93
- replacement[ indexToSelect ].clientId,
94
- initialPosition
95
- );
96
- } );
97
- }
98
-
99
80
  return ( forward ) => {
100
81
  if ( forward ) {
101
82
  const nextBlockClientId = getNextId( clientId );
102
83
 
103
84
  if ( ! nextBlockClientId ) {
104
- switchToDefaultBlockType( forward );
85
+ onMerge( forward );
105
86
  return;
106
87
  }
107
88
 
@@ -134,7 +115,7 @@ export default function useMerge( clientId ) {
134
115
  mergeBlocks( trailingId, clientId );
135
116
  } );
136
117
  } else {
137
- switchToDefaultBlockType( forward );
118
+ onMerge( forward );
138
119
  }
139
120
  }
140
121
  };
@@ -88,7 +88,6 @@
88
88
  },
89
89
  "supports": {
90
90
  "align": [ "wide", "full" ],
91
- "anchor": true,
92
91
  "html": false,
93
92
  "inserter": true,
94
93
  "typography": {
@@ -307,9 +307,6 @@ function block_core_navigation_get_fallback_blocks() {
307
307
  $page_list_fallback = array(
308
308
  array(
309
309
  'blockName' => 'core/page-list',
310
- 'attrs' => array(
311
- '__unstableMaxPages' => 4,
312
- ),
313
310
  ),
314
311
  );
315
312
 
@@ -7,11 +7,7 @@
7
7
  "description": "Display a list of all pages.",
8
8
  "keywords": [ "menu", "navigation" ],
9
9
  "textdomain": "default",
10
- "attributes": {
11
- "__unstableMaxPages": {
12
- "type": "number"
13
- }
14
- },
10
+ "attributes": {},
15
11
  "usesContext": [
16
12
  "textColor",
17
13
  "customTextColor",
@@ -299,11 +299,6 @@ function render_block_core_page_list( $attributes, $content, $block ) {
299
299
 
300
300
  $nested_pages = block_core_page_list_nest_pages( $top_level_pages, $pages_with_children );
301
301
 
302
- // Limit the number of items to be visually displayed.
303
- if ( ! empty( $attributes['__unstableMaxPages'] ) ) {
304
- $nested_pages = array_slice( $nested_pages, 0, $attributes['__unstableMaxPages'] );
305
- }
306
-
307
302
  $is_navigation_child = array_key_exists( 'showSubmenuIcon', $block->context );
308
303
 
309
304
  $open_submenus_on_click = array_key_exists( 'openSubmenusOnClick', $block->context ) ? $block->context['openSubmenusOnClick'] : false;
@@ -189,6 +189,10 @@ function build_template_part_block_area_variations() {
189
189
  * @return array Array containing the block variation objects.
190
190
  */
191
191
  function build_template_part_block_instance_variations() {
192
+ // Block themes are unavailable during installation.
193
+ if ( wp_installing() ) {
194
+ return array();
195
+ }
192
196
  $variations = array();
193
197
  $template_parts = get_block_templates(
194
198
  array(